LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-13-2010, 09:04 AM   #1
kopper27
Member
 
Registered: Nov 2009
Posts: 147

Rep: Reputation: 16
monitor filesystems and notify @


hi guys

I need to monitor my filesystems and get an email when the status is warning >=80 and critical >=90.
I am not very good for scripting so I found an script but is not working for me

This Red Hat Enterprise 5.0

Script

Code:
ADMIN="me@somewher.com"
# set alert level 90% is default
ALERT=90
df -H | 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)" |
     mail -s "Alert: Almost out of disk space $usep" $ADMIN
  fi
done
I am getting these errors

Code:
./test: line 9: [: /dev/mapper/VolGroup00-root: integer expression expected
./test: line 9: [: /: integer expression expected
./test: line 9: [: /dev/mapper/VolGroup00-var: integer expression expected
./test: line 9: [: /var: integer expression expected
now this is my df -h command

Code:
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-root
                      120G   20G   94G  18% /
/dev/sda1              99M   12M   83M  12% /boot
tmpfs                 1.7G     0  1.7G   0% /dev/shm
/dev/mapper/VolGroup00-var
                      9.7G  1.3G  7.9G  15% /var
any idea what could be causing that and how to fix it?

or maybe someone has a better script?

thanks a lot

Last edited by kopper27; 01-13-2010 at 09:19 AM.
 
Old 01-13-2010, 12:16 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Use "df -HP" to begin with, so you get all output for one volume
on one line ....
 
Old 01-13-2010, 01:06 PM   #3
kopper27
Member
 
Registered: Nov 2009
Posts: 147

Original Poster
Rep: Reputation: 16
thanks a but now I get no output from the script

./script and nothing comes up

what could be?
 
Old 01-13-2010, 01:25 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Maybe the fact that none of the disks are full?
 
Old 01-13-2010, 01:36 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Btw, you could significantly shorten the script
Code:
ALERT=90
df -HP | awk '!/^Filesystem|tmpfs|cdrom/ { print gensub( /%/, "", "1",$5) " " $1 }' | while read usep partition
do
  if [ $usep -ge $ALERT ]; then
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" | mail -s "Alert: Almost out of disk space $usep" $ADMIN
  fi
done
 
Old 01-13-2010, 04:03 PM   #6
kopper27
Member
 
Registered: Nov 2009
Posts: 147

Original Poster
Rep: Reputation: 16
looks like that's the thing...

now I get this

Code:
You must specify direct recipients with -s, -c, or -b.
I am testing the script with a server with a filesystem 85%
 
Old 01-13-2010, 04:09 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Ooops ... if you copied my version:
the definition of ADMIN="yadda@blah.org" is missing.

Plus you may have to play with \" around the subject,
but that's untested.
 
Old 01-20-2010, 03:32 PM   #8
kopper27
Member
 
Registered: Nov 2009
Posts: 147

Original Poster
Rep: Reputation: 16
hi again

This what I have sorry I did not use your code
looks like it working what I don't know (feel very stupid for it)
how to test it using email do I need a SMTP Server or what?

if someone can test it

basically it has 2 type of messages WARNING and ALERT


Code:
ADMIN="karlo@yahoo.com"
# set alert level 90% is default
WARNING=70
ALERT=85
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 $WARNING ] && [ $usep -lt $ALERT ]; then
  echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)"
  fi
  if [ $usep -ge $ALERT ]; then
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" #|
    # mail -s "Alert: Almost out of disk space $usep" $ADMIN
  fi
done
 
Old 01-20-2010, 04:47 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You'll need to ensure sendmail (or equiv) is running . A mail server is pretty std as the system frequently talks to itself. You can check by logging in as root and running

mailx

at the cmd line.
There should be a few msgs there.

Note that by default sendmail is installed to only listen to localhost(127.0.0.1).
If you want it to listen to other systems, amend

DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')

to

dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

in /etc/mail/sendmail.mc & restart it ('service sendmail restart' iirc).
 
Old 01-21-2010, 10:13 AM   #10
kopper27
Member
 
Registered: Nov 2009
Posts: 147

Original Poster
Rep: Reputation: 16
let me see If I got this

from this
Code:
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
to this
Code:
dnl # DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
or
Code:
DAEMON_OPTIONS(`Port=smtp,Name=MTA')dnl
that's it? I don't need to specify an SMTP Server?
my question is because as you see above the script I will be running
once it finds a problem will have to send me an email ton my external @ kopper27@xxxxx.com

thanks

thanks a lot

Last edited by kopper27; 01-21-2010 at 10:15 AM.
 
Old 01-21-2010, 05:14 PM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You only need to worry about that if you want to accept incoming emails to this machine from other systems. Outgoing is not a problem.
You can use

ps -ef|grep sendmail

to see if it's running. That edit is only relevant to sendmail; other MTAs have different cfgs.
 
Old 01-22-2010, 08:44 AM   #12
kopper27
Member
 
Registered: Nov 2009
Posts: 147

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by chrism01 View Post
You only need to worry about that if you want to accept incoming emails to this machine from other systems. Outgoing is not a problem.
You can use

ps -ef|grep sendmail

to see if it's running. That edit is only relevant to sendmail; other MTAs have different cfgs.
so you mean I only need the sendmail up and running(no configuration at all) and if it has internet connection it will send me an email to my kopper27@xxxxx.com

mmm If I got it correctly that would be cool
 
  


Reply



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
Filesystems delta_simon Linux - Software 1 09-13-2007 10:11 PM
Filesystems debnewb Linux - General 2 04-19-2005 04:19 PM
Filesystems Jeebizz Slackware 1 10-18-2004 01:18 PM
windows filesystems vs. linux filesystems irfanhab General 8 05-25-2004 07:21 AM
Filesystems narusegawa Slackware 1 03-27-2003 07:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:51 AM.

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
Open Source Consulting | Domain Registration