LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
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

Tags used in this thread
Popular LQ Tags , ,

Reply
 
Thread Tools
Old 11-06-2009, 02:26 AM   #1
allancuntapay
LQ Newbie
 
Registered: Apr 2007
Posts: 17
Blog Entries: 1
Thanked: 0
home directory size monitoring script


[Log in to get rid of this advertisement]
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
linux allancuntapay is offline  
Tag This Post , ,
Reply With Quote
Old 11-06-2009, 03:24 AM   #2
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Etch/Lenny/Squeeze
Posts: 2,296
Thanked: 89
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
linux jlinkels is offline     Reply With Quote
Thanked by:
Old 11-06-2009, 03:34 AM   #3
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 1,636
Thanked: 18
Or use quotas, that's kind of what they're for.
linux tuxdev is offline     Reply With Quote
Thanked by:
Old 11-06-2009, 03:37 AM   #4
indiajoe
Member
 
Registered: Jan 2009
Location: India
Distribution: Slax atma
Posts: 48
Thanked: 9
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
linux indiajoe is offline     Reply With Quote
Thanked by:
Old 11-06-2009, 06:51 AM   #5
allancuntapay
LQ Newbie
 
Registered: Apr 2007
Posts: 17
Blog Entries: 1
Thanked: 0

Original Poster
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
windows_vista allancuntapay is offline     Reply With Quote
Old 11-06-2009, 07:09 AM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 1,808
Blog Entries: 5
Thanked: 114
do it with just awk. No need grep or sed
Code:
$ df /home | awk '$5+0>86{print "overload"}'
overload
linuxfedora ghostdog74 is offline     Reply With Quote
Thanked by:
Old 11-07-2009, 07:59 AM   #7
allancuntapay
LQ Newbie
 
Registered: Apr 2007
Posts: 17
Blog Entries: 1
Thanked: 0

Original Poster
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.
windows_vista allancuntapay is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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 06:58 AM
Home Directory Size? Carlwill Linux - General 3 12-13-2005 02:04 PM
/home/directory size limit Smokey Slackware 2 11-04-2004 04:11 PM
Urgent !!! monitoring directory size using bash juby Programming 4 07-22-2004 06:47 AM
How to LIMIT my HOME DIRECTORY SIZE??? juliann Linux - Networking 2 07-21-2004 10:08 AM


All times are GMT -5. The time now is 08:36 AM.

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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration