AOA,
I have a following file systems:
/dev/sda1 20G 8.1G 11G 43% /
/dev/sda3 40G 33G 5.3G 86% /d01
/dev/sdb 148G 113G 28G 81% /san
/dev/sdc 50G 84M 47G 1% /san01
/dev/sdd 403G 298G 85G 78% /san00
I need a script that if any file system exceed to 90% than email me.
Also if System load (w command) exceed to 5.00 then also mail me
Scripts Required!
-
- Naik
- Posts: 68
- Joined: Thu Aug 07, 2008 6:09 pm
- Location: karachi
Re: Scripts Required!
Following script will send you an email once specified filesystems go over 90%
#!/bin/bash
output1=`df -lh | grep /dev/sda1 | awk '{print $5}' | sed 's/[!@#\$%^&*()]//g'`
output5=`df -lh | grep /dev/sda3 | awk '{print $5}' | sed 's/[!@#\$%^&*()]//g'`
output2=`df -lh | grep /dev/sdb | awk '{print $5}' | sed 's/[!@#\$%^&*()]//g'`
output3=`df -lh | grep /dev/sdc | awk '{print $5}' | sed 's/[!@#\$%^&*()]//g'`
output4=`df -lh | grep /dev/sdd | awk '{print $5}' | sed 's/[!@#\$%^&*()]//g'`
mail_address="your_mail_address"
function1(){
if [ $output1 -ge 90 ]
then
echo "filesystem Alert on "sda1"" | mail -s "filesystem alert" $mail_address
else
echo "nothing"
fi
}
function2(){
if [ $output2 -ge 90 ]
then
echo "filesystem Alert on sda3" | mail -s "filesystem alert" $mail_address
else
echo "nothing"
fi
}
function3() {
if [ $output3 -ge 90 ]
then
echo "filesystem Alert on sdc" | mail -s "filesystem alert" $mail_address
else
echo "nothing"
fi
}
function4() {
if [ $output4 -ge 90 ]
then
echo "filesystem Alert on sdd" | mail -s "filesystem alert" $mail_address
else
echo "nothing"
fi
}
function5() {
if [ $output5 -ge 90 ]
then
echo "filesystem Alert on sdb" | mail -s "filesystem alert" $mail_address
else
echo "nothing"
fi
}
function1
function2
function3
function4
Regards,
Ghulam Yaseen
http://friendspak.com
#!/bin/bash
output1=`df -lh | grep /dev/sda1 | awk '{print $5}' | sed 's/[!@#\$%^&*()]//g'`
output5=`df -lh | grep /dev/sda3 | awk '{print $5}' | sed 's/[!@#\$%^&*()]//g'`
output2=`df -lh | grep /dev/sdb | awk '{print $5}' | sed 's/[!@#\$%^&*()]//g'`
output3=`df -lh | grep /dev/sdc | awk '{print $5}' | sed 's/[!@#\$%^&*()]//g'`
output4=`df -lh | grep /dev/sdd | awk '{print $5}' | sed 's/[!@#\$%^&*()]//g'`
mail_address="your_mail_address"
function1(){
if [ $output1 -ge 90 ]
then
echo "filesystem Alert on "sda1"" | mail -s "filesystem alert" $mail_address
else
echo "nothing"
fi
}
function2(){
if [ $output2 -ge 90 ]
then
echo "filesystem Alert on sda3" | mail -s "filesystem alert" $mail_address
else
echo "nothing"
fi
}
function3() {
if [ $output3 -ge 90 ]
then
echo "filesystem Alert on sdc" | mail -s "filesystem alert" $mail_address
else
echo "nothing"
fi
}
function4() {
if [ $output4 -ge 90 ]
then
echo "filesystem Alert on sdd" | mail -s "filesystem alert" $mail_address
else
echo "nothing"
fi
}
function5() {
if [ $output5 -ge 90 ]
then
echo "filesystem Alert on sdb" | mail -s "filesystem alert" $mail_address
else
echo "nothing"
fi
}
function1
function2
function3
function4
Regards,
Ghulam Yaseen
http://friendspak.com
-
- Naik
- Posts: 68
- Joined: Thu Aug 07, 2008 6:09 pm
- Location: karachi
Re: Scripts Required!
following script will send you email once the system load goes over 5
output1=`uptime | awk '{print $11}' | cut -c 1`
mail_address="your_mail_address"
if [ $output1 -ge 5 ]
then
echo "System load is gone over 5" | mail -s "system load warning" $mail_address
else
echo "nothing"
fi
Regards,
Ghulam Yaseen
http://friendspak.com
output1=`uptime | awk '{print $11}' | cut -c 1`
mail_address="your_mail_address"
if [ $output1 -ge 5 ]
then
echo "System load is gone over 5" | mail -s "system load warning" $mail_address
else
echo "nothing"
fi
Regards,
Ghulam Yaseen
http://friendspak.com
-
- Naik
- Posts: 68
- Joined: Thu Aug 07, 2008 6:09 pm
- Location: karachi
regarding scripts
but do remember, more the scripts you run...more the system memory and cpu usage will happen.....
Code: Select all
#!/bin/sh
IFS=
maybemail=`df | awk '$1 ~ /^\// {if ($5 > 90) {printf "%s is at %s\n", $6, $5}}';`
if [ -n "$maybemail" ]; then
echo $maybemail | mail -s "file systems on `hostname` over 90%"
fi
Code: Select all
#!/bin/sh
if ! `awk '$1 > 5.00 { exit 1; }' /proc/loadavg`; then
cat /proc/loadavg | mail -s "load average on `hostname` is greater than 5.00"
fi
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
-
- Naik
- Posts: 68
- Joined: Thu Aug 07, 2008 6:09 pm
- Location: karachi
simplified script
well......lambda your script seems much more simple than mine.i just did a try, as i am not an expert
lambda wrote:Code: Select all
#!/bin/sh IFS= maybemail=`df | awk '$1 ~ /^\// {if ($5 > 90) {printf "%s is at %s\n", $6, $5}}';` if [ -n "$maybemail" ]; then echo $maybemail | mail -s "file systems on `hostname` over 90%" fi
run them with cron.Code: Select all
#!/bin/sh if ! `awk '$1 > 5.00 { exit 1; }' /proc/loadavg`; then cat /proc/loadavg | mail -s "load average on `hostname` is greater than 5.00" fi