Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have written a scipt that will report when a drive is down, but i finding if the status of the drive is UP, then "while read LINE" ignores the IF statement. I want the script to print the echo "All the drives are up". How can i modify the script so that else exception is not ignored.
vmoprcmd command give you the following output as show below:
Drv Type Control
0 hcart2 DOWN-ACS
1 hcart2 DOWN-ACSvmoprcmd | grep -i DOWN | awk '{print $1,$3}' |
while read LINE
do
if [ $LINE != "" ];then
..........
else
echo "All the drives are up" >> /tmp/drive_status
fi
done
.....Thanks
Junes
King Regards
Junes

Your problem is that if all the drives are up nothing is grepped and, thus, your while loop never executes.
I don't use the vmoprcmd, so I placed the output in file prcmd.txt. If the word "DOWN" isn't found, the grep fails setting the unix exit code to non-zero meaning all the drives are up:
#!/bin/ksh
grep -i "DOWN" prcmd.txt > myfile.txt
if [ $? != 0 ]
then
echo "All the drives are up"
fi
# end script.Now, if the myfile.txt size is greater than 0, you have a problem drive:
if [ -s myfile.txt ]
then
echo "Process myfile.txt to find the bad drive"
fi

Thanks for that, it worked a treat!!
if [ -s myfile.txt ]
then
echo "Process myfile.txt to find the bad drive"
fiKing Regards
Junes

![]() |
sftp unix script
|
changing col(1) command s...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |