LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 10-21-2007, 12:30 AM   #1
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian, OS X
Posts: 1,274

Rep: Reputation: 99
Question Shell script to monitor or watch the disk space.... small help needed


hi all,

I just found this script on net. However, im facing some problems running it.


Code:
#!/bin/bash
ALERT=70
ssh 10.61.37.176 df -H  > /tmp/df.out
cat /tmp/df.out | 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
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)"

   fi
done


I am using Sun OS. df -H, and grep -E options are not running.

I am getting these errors.

df: unknown option: H
Usage: df [-F FSType] [-abegklntVv] [-o FSType-specific_options] [directory | block_device | resource]
grep: illegal option -- E
Usage: grep -hblcnsviw pattern file . . .



pls help out !!

Thanks in adv.
 
Old 10-21-2007, 05:35 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

You could use df -k or a plain df. The -H part is to make the output human readable (15086632 vs 16G). The -k option shows the output in 1k blocks.

Try using egrep instead of grep.

BTW: The manpages can help you with the options (and other neat info).

Hope this helps.
 
Old 10-21-2007, 06:37 AM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Quote:
Originally Posted by vikas027 View Post
hi all,

I just found this script on net. However, im facing some problems running it.


Code:
#!/bin/bash
ALERT=70
ssh 10.61.37.176 df -H  > /tmp/df.out
cat /tmp/df.out | 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
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)"

   fi
done


I am using Sun OS. df -H, and grep -E options are not running.

I am getting these errors.

df: unknown option: H
Usage: df [-F FSType] [-abegklntVv] [-o FSType-specific_options] [directory | block_device | resource]
grep: illegal option -- E
Usage: grep -hblcnsviw pattern file . . .



pls help out !!

Thanks in adv.
you can't just grab any scripts from the internet and expect it to run on your systems without any flaws. you got to change/amend it to suit your environment! here's a script you can use. change it to suit your needs
Code:
awk ' BEGIN {
    recipient = "root" #configure your recipients
    threshold = "90"
    df = "/bin/df -k"
    while ( ( df |getline line ) > 0 ) {
      split(line,array," ")
      if ( int(array[5]) > threshold ) {      
        email="/usr/bin/mail "recipient 
        print "Filesystem " array[1] " hits the threshold " threshold ".Value: " array[5] | email
        close(email)
      }    
    }
    close(df)    
}'
 
Old 10-21-2007, 06:42 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

An addition to ghostdog74's solution: If this has to run on a SUN box, you might need to change awk into nawk. SUN's default awk is kinda limited.

Hope this helps.
 
Old 10-21-2007, 09:22 AM   #5
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian, OS X
Posts: 1,274

Original Poster
Rep: Reputation: 99
Smile

Quote:
Originally Posted by druuna View Post
Hi,

You could use df -k or a plain df. The -H part is to make the output human readable (15086632 vs 16G). The -k option shows the output in 1k blocks.

Try using egrep instead of grep.

BTW: The manpages can help you with the options (and other neat info).

Hope this helps.
thanks to everybody, i really tried running through man pages, but cudnt find something useful. i am new to scripting, just 2-3 days old.
i just changed grep to egrep & df -k to df -h, IT WORKED.
will remember this in future.
THANKS AGAIN.
 
Old 10-21-2007, 11:04 AM   #6
PAix
Member
 
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195

Rep: Reputation: 40
All goo solid info. nawk (new awk was circa 1989 and greatly extended the original) although significantly behind awk as we know it today (gawk).
The df -h (human) seems to be a Linux feature. As stated df -k displays in kbytes rather than the default which is in blocks, presumably exceedingly useful to someone somewhere, but I haven't found them yet.
 
  


Reply


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
LXer: Perl script to monitor disk space and send an email alert LXer Syndicated Linux News 1 02-23-2007 02:12 PM
small script needed samac Slackware 2 02-10-2007 11:11 AM
small shell script required demigor Programming 6 08-08-2005 05:38 PM
FDISK! /var too big; / too small, reallocate disk space pauljtester Linux - General 2 08-05-2004 09:10 PM
extremely urgent help needed - disk space h/w Linux - Newbie 3 10-08-2003 11:59 AM


All times are GMT -5. The time now is 06:41 PM.

Main Menu
Advertisement
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