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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-13-2010, 09:04 AM
|
#1
|
Member
Registered: Nov 2009
Posts: 147
Rep:
|
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.
|
|
|
01-13-2010, 12:16 PM
|
#2
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
Use "df -HP" to begin with, so you get all output for one volume
on one line ....
|
|
|
01-13-2010, 01:06 PM
|
#3
|
Member
Registered: Nov 2009
Posts: 147
Original Poster
Rep:
|
thanks a but now I get no output from the script
./script and nothing comes up
what could be?
|
|
|
01-13-2010, 01:25 PM
|
#4
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
Maybe the fact that none of the disks are full?
|
|
|
01-13-2010, 01:36 PM
|
#5
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
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
|
|
|
01-13-2010, 04:03 PM
|
#6
|
Member
Registered: Nov 2009
Posts: 147
Original Poster
Rep:
|
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%
|
|
|
01-13-2010, 04:09 PM
|
#7
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
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.
|
|
|
01-20-2010, 03:32 PM
|
#8
|
Member
Registered: Nov 2009
Posts: 147
Original Poster
Rep:
|
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
|
|
|
01-20-2010, 04:47 PM
|
#9
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,430
|
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).
|
|
|
01-21-2010, 10:13 AM
|
#10
|
Member
Registered: Nov 2009
Posts: 147
Original Poster
Rep:
|
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.
|
|
|
01-21-2010, 05:14 PM
|
#11
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,430
|
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.
|
|
|
01-22-2010, 08:44 AM
|
#12
|
Member
Registered: Nov 2009
Posts: 147
Original Poster
Rep:
|
Quote:
Originally Posted by chrism01
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
|
|
|
All times are GMT -5. The time now is 11:43 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|