Current file system utilization alert shell script

My first shell script .To check and send a mail for current filestem
utilization more then threshold.Here our threshold value is 95%.

Create a file as like below and save in which server need have the
alert.

[root@localhost ~]#vi myfirstshell.sh

#!/bin/sh
echo "Following volumes in $(hostname)as on $(date) needs attention"
> /var/tmp/threshold
df -h | awk '$5 >= "95%" {print $0}' | awk '{print $6"\t\t\t"$5}' >> /
var/tmp/threshold
mailx -s "Threshold Alert" yourmail-id@domain.com < /var/tmp/threshold
echo "" >> /var/tmp/threshold

:wq

[root@localhost ~]# chmod u+x myfirstshell.sh

[root@localhost ~]# sh -x myfirstshell.sh
++ hostname
++ date
+ echo 'Following volumes in localhost.localdomainas on Thu May 12
01:09:19 IST 2011 needs attention'
+ df -h
+ awk '$5 >= "95%" {print $0}'
+ awk '{print $6"\t\t\t"$5}'
+ echo ''
[root@localhost ~]#

Check output in the file .

As well as we would received the mail too.

[root@localhost ~]# cat /var/tmp/threshold
Following volumes in localhost.localdomainas on Thu May 12 01:09:19
IST 2011 needs attention
Mounted Use%
/ 95%

[root@localhost ~]#

No comments:

Post a Comment

Thank You for your Comments, We will read and response you soon...