Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with if and else

Status
Not open for further replies.

Marcel1958

Technical User
Oct 11, 2001
38
NL
I wrote the an script to check the file systems.


df -k | tr -d "%" | grep dev |
while read filesystem blocks free gebruik A1 iused mounted

do


if

[ "$gebruik" -gt "50" ] && [ "$mounted" = "/var/psf" ] |
[ "$gebruik" -gt "90" ] && [ "$mounted" = "/var/psf/segments" ]
then
MESSAGE="$filesystem is $gebruik % full and mounted on $mounted"
echo $MESSAGE


else

if
[ "$gebruik" -gt "60" ]
then
MESSAGE="$filesystem is xx $gebruik % full and mounted on $mounted"
echo $MESSAGE
fi
fi


done



The result of this is:

/dev/hd2 is xx 62 % full and mounted on /usr
/dev/hd9var is xx 66 % full and mounted on /var
/dev/lvpd is xx 66 % full and mounted on /var/pd
/dev/lvpsf is xx 89 % full and mounted on /var/psf
/dev/lvpsfs is xx 85 % full and mounted on /var/psf/segments



Why do ik get the line
/dev/lvpsf is xx 89 % full and mounted on /var/psf
while i excluded it in the if statement:


 
Because 89 -gt 90 is false.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Indeed. But why get i the line

/dev/lvpsfs is xx 85 % full and mounted on /var/psf/segments

 
Because:
[ "$gebruik" -gt "50" ] && [ "$mounted" = "/var/psf" ] is false
[ "$gebruik" -gt "90" ] && [ "$mounted" = "/var/psf/segments" ] is false
[ "$gebruik" -gt "60" ] is true

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV, but i get the message from the else statement :
/dev/lvpsf is xx 89 % full and mounted on /var/psf

while
[ "$gebruik" -gt "50" ] && [ "$mounted" = "/var/psf" ]
is true in the if statement
 
Can you please repost the script as I'm not sure about the higlighted stuff below:
[ "$gebruik" -gt "50" ] && [ "$mounted" = "/var/psf" ][highlight] | [/highlight]


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
[ "$gebruik" -gt "50" ] && [ "$mounted" = "/var/psf" ] |
[ "$gebruik" -gt "90" ] && [ "$mounted" = "/var/psf/segments" ]

I think what you want here is:

Code:
     ([ "$gebruik" -gt "50" ] && [ "$mounted" = "/var/psf" ]) ||
     ([ "$gebruik" -gt "90" ] && [ "$mounted" = "/var/psf/segments" ])

A single | is a pipe, || indicates "or". The parentheses make sure that it's the two "and" clauses that are or'ed.

Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top