LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   home directory size monitoring script (https://www.linuxquestions.org/questions/programming-9/home-directory-size-monitoring-script-767241/)

allancuntapay 11-06-2009 01:26 AM

home directory size monitoring script
 
newbie here. am doing script on monitoring my directory /home that if it gets greater or equal to 86, then it will prompt me overload, else its fine.



please help what's wrong with my script. thanks


SIZE='df -h /home | /bin/awk '{ print $5 }' | grep -v Use% | sed '/%//''
if [ $SIZE >= "86" ]; then
echo "overload"
else
echo "ok"
fi

Allan

jlinkels 11-06-2009 02:24 AM

One obvious error is $SIZE > "86" which should be $SIZE -gt 86.

Another problem might be grep Use%, I would grep Use\%. In Linux everything appearing on top of the number keys is suspicious and might need to be escaped.

Finally run you script with sh -x yourscript

jlinkels

tuxdev 11-06-2009 02:34 AM

Or use quotas, that's kind of what they're for.

indiajoe 11-06-2009 02:37 AM

Hi,
Following is the corrected code. Another error was that you used /%// instead of s/%// in sed .
Code:

#!/bin/sh
SIZE=`df -h /home/YOU | /bin/awk '{ print $5 }' | grep -v Use% | sed 's/%//'`
if [ $SIZE -ge 86 ]; then
echo "overload"
else
echo "ok"
fi

-Cheers
indiajoe

allancuntapay 11-06-2009 05:51 AM

Thanks a lot. that worked. :)



Quote:

Originally Posted by indiajoe (Post 3746750)
Hi,
Following is the corrected code. Another error was that you used /%// instead of s/%// in sed .
Code:

#!/bin/sh
SIZE=`df -h /home/YOU | /bin/awk '{ print $5 }' | grep -v Use% | sed 's/%//'`
if [ $SIZE -ge 86 ]; then
echo "overload"
else
echo "ok"
fi

-Cheers
indiajoe


ghostdog74 11-06-2009 06:09 AM

do it with just awk. No need grep or sed
Code:

$ df /home | awk '$5+0>86{print "overload"}'
overload


allancuntapay 11-07-2009 06:59 AM

Quote:

Originally Posted by ghostdog74 (Post 3746906)
do it with just awk. No need grep or sed
Code:

$ df /home | awk '$5+0>86{print "overload"}'
overload


thank you very much.. Am learning a lot in here.


All times are GMT -5. The time now is 11:18 PM.