Linux - NewbieThis 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.
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.
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
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
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
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
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
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.