global scope of variable

Posted by shantanuo on Stack Overflow See other posts from Stack Overflow or by shantanuo
Published on 2009-11-24T12:22:55Z Indexed on 2010/04/19 2:03 UTC
Read the original article Hit count: 374

Filed under:
|

The following shell scrip will check the disk space and change the variable "diskfull" to 1 if the usage is more than 10% The last echo always shows 0 I tried the global diskfull=1 in the if clause but it did not work. How do I change the variable to 1 if the disk consumed is more than 10%

#!/bin/sh
diskfull=0

ALERT=10
df -HP | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
  #echo $output
  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $output | awk '{ print $2 }' )
  if [ $usep -ge $ALERT ]; then

diskfull=1
exit
  fi
done

echo $diskfull

© Stack Overflow or respective owner

Related posts about shell

Related posts about shell-scripting