Computing.Net > Forums > Unix > While read is ignoring if statement

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

While read is ignoring if statement

Reply to Message Icon

Name: Junes
Date: June 7, 2006 at 04:18:48 Pacific
OS: Unix
CPU/Ram: na
Product: na
Comment:

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-ACS

vmoprcmd | 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



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: June 7, 2006 at 09:35:19 Pacific
Reply:

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


0

Response Number 2
Name: Junes
Date: June 9, 2006 at 03:22:56 Pacific
Reply:

Thanks for that, it worked a treat!!

if [ -s myfile.txt ]
then
echo "Process myfile.txt to find the bad drive"
fi

King Regards

Junes


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


sftp unix script changing col(1) command s...



Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: While read is ignoring if statement

Test sed output using IF statement www.computing.net/answers/unix/test-sed-output-using-if-statement/7299.html

unix if statement www.computing.net/answers/unix/unix-if-statement/8122.html

While Read issue www.computing.net/answers/unix/while-read-issue/8140.html