#!/bin/sh
# 60 # timeout of 60 seconds

# MegaRAID set good utility
# To fix disks which are UBAD or FOREIGN flags
# Written by Andy Henson
# Copyright (C) 2016,2017 New Zexia Ltd

P=/usr/share/venusd/EXEC

# delete preserved cache and foreign flags
$P/storcli /c0/vall delete preservedcache
$P/storcli /c0/fall del

# now read all disk info
SALL=`$P/storcli /call show | grep SATA`
while read A X1 X2 X3 CAP CAP2 X4 X5 X6 X7 X8 M1 M2 X10; do
	E=${A/:*/}
	S=${A/*:/}
	DISK=/se${E}s$S
	STATE=${X2^^}
	echo "$DISK is $STATE"
	if [ "$STATE" == "UBAD" ]; then
		echo "$DISK: set good"
		venuslogd -m "D Disk: MegaRAID: $DISK: set good"
		$P/storcli /c0/e$E/s$S set good
	fi
done <<<"$SALL"

