LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-06-2009, 01:26 AM   #1
allancuntapay
LQ Newbie
 
Registered: Apr 2007
Posts: 17
Blog Entries: 1

Rep: Reputation: 0
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
 
Old 11-06-2009, 02:24 AM   #2
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,163

Rep: Reputation: 505Reputation: 505Reputation: 505Reputation: 505Reputation: 505Reputation: 505
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
 
Old 11-06-2009, 02:34 AM   #3
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,014

Rep: Reputation: 115Reputation: 115
Or use quotas, that's kind of what they're for.
 
Old 11-06-2009, 02:37 AM   #4
indiajoe
Member
 
Registered: Jan 2009
Location: India
Distribution: Porteus atma
Posts: 84

Rep: Reputation: 21
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
 
Old 11-06-2009, 05:51 AM   #5
allancuntapay
LQ Newbie
 
Registered: Apr 2007
Posts: 17
Blog Entries: 1

Original Poster
Rep: Reputation: 0
Thanks a lot. that worked.



Quote:
Originally Posted by indiajoe View Post
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
 
Old 11-06-2009, 06:09 AM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,696
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
do it with just awk. No need grep or sed
Code:
$ df /home | awk '$5+0>86{print "overload"}'
overload
 
Old 11-07-2009, 06:59 AM   #7
allancuntapay
LQ Newbie
 
Registered: Apr 2007
Posts: 17
Blog Entries: 1

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ghostdog74 View Post
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.
 
  


Reply

Tags
monitoring, script, size


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash - size of home directory klavuzkarga Linux - Newbie 9 12-17-2007 05:58 AM
Home Directory Size? carlosinfl Linux - General 3 12-13-2005 01:04 PM
/home/directory size limit Smokey Slackware 2 11-04-2004 03:11 PM
Urgent !!! monitoring directory size using bash juby Programming 4 07-22-2004 05:47 AM
How to LIMIT my HOME DIRECTORY SIZE??? juliann Linux - Networking 2 07-21-2004 09:08 AM


All times are GMT -5. The time now is 10:28 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration