Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure one script to send mail alerts if filesystem is reaching 90%

SOLVED
Go to solution
Highlighted
senthil_kumar_2
Regular Advisor

How to configure one script to send mail alerts if filesystem is reaching 90%

Hi All,

I have written one script and configured that in crontab for sending mail alerts if filsystem is reaching thrushold of 90%.

For example:

1)#vi /usr/local/bin/disk_full.sh

#!/bin/sh
bdf | awk 'z[split($5,z,"%")-1]>90' | mailx -r senthil.kumar@emdiesels.com -s "$HOST Filesystems > 90%" abc@yahoo.co.in


2)crontab -e

########### Send mail alerts if any filesystem reaches thrushold 90%##########
1 * * * * /usr/local/bin/disk_full.sh
##########################################################


I have written above script to check if any of the filesystes is reaching thrush hold of 90% for every one hour and send mails if any of the filesystems is reached 90%.

It is working fine.

But I have following issues.

My Issue:

I am getting blank mail alerts even if any of filesystems is not reaching 90%. Therefore I am getting one mail from for ever one hour even if there is no filesystem is reached thrush hold of 90%.

My Requirement:

I would like to receive mail alerts only if any of the file system is reaching thrush hold of 90% but not for empty (If there is no filesystems reached 90%).

How to resolve this.



15 REPLIES
James R. Ferguson
Acclaimed Contributor

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Hi Senthil:

As written, regardless of any output, 'mailx' is spawned by the pipe. Hence, you unconditionally get mail regardless of the utilization threshold.

You could do:

# [ -z "$(bdf|awk 'z[split($5,z,"%")-1]>90')" ] || mailx ...

...or capture the output; test the output for emptiness and email the non-empty result.

# RESULTS=$(bdf|awk 'z[split($5,z,"%")-1]>90')
# [ -z "${RESULTS}" ] || mailx ...

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Hi (again) Senthil:

By the way, you have a recently growing number of questions you have asked without any point assignment whatsoever:

http://forums.itrc.hp.com/service/forums/pageList.do?userId=WW220552&listType=unassigned&forumId=1

...JRF...

Suraj K Sankari
Honored Contributor

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Hi,
Got so many thread see the below
http://forums11.itrc.hp.com/service/forums/questionanswer.do?admit=109447626+1278423920446+28353475&threadId=1130400
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1336882
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1100009
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1064880
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=800551
here is the script i am using.
#!/usr/bin/ksh

PATH=/usr/bin:/usr/sbin
CONF_FILE=fs_check.conf.txt

# Source default env vars
. ${CONF_FILE}

# Count number of FS to check
i=${#FS[*]}

# Check each Filesystem
while [ "$(($i-1))" -ge "0" ]
do
let i=i-1
PCT=$(bdf ${FS[$i]} | awk '/\// {print $5}' | tr -d '%')
if [ ${PCT} -gt ${TRESH[$i]} ]
then
if [ "90" -le ${PCT} ]
then
echo "FATAL: Out of disk space for ${FS[$i]}!" | mailx -s FS_FATAL me@company.com
else
echo "WARNING: Threshold exceeded for ${FS[$i]}, it is now ${PCT}." | mailx -s FS_WARNING me@company.com
fi
fi
done
exit 0


Suraj
senthil_kumar_2
Regular Advisor

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Hi James,

I have modified the file "/usr/local/bin/disk_full.sh" as following


# more /usr/local/bin/disk_full.sh

#!/bin/bash
RESULTS=$(bdf | awk 'z[split($5,z,"%")-1]>90')
[ -z "${RESULTS}" ] | mailx -r senthil.kumar@emdiesels.com -s "$HOST Filesystems > 90%" senthil.kumar@emdiesels.com



Still I am getting alerts with empty message.

How to resolve.
James R. Ferguson
Acclaimed Contributor

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Hi (again) Senthil:

> [ -z "${RESULTS}" ] | mailx ...

You didn't copy what I wrote and made the same mistake as you originally had. You don't want a pipe ('|') you want the logical relation ('||') as:

# [ -z "${RESULTS}" ] || mailx ...

...which says if the variable called RESULTS is not empty, run the command 'mailx'.

Regards!

...JRF...
senthil_kumar_2
Regular Advisor

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Hi James,

Still the issue is not resolved.

1)# more disk.sh
#!/bin/bash
RESULTS=$(bdf | awk 'z[split($5,z,"%")-1]>90')
[ -z "${RESULTS}" ] || mailx -r abc@company.com -s "$HOST Filesystems > 90%" abc@company.com


2)# ll disk.sh

-rwxr-xr-x 1 root root 145 Jul 6 09:51 disk.sh


3)#./disk.sh

Now it is hanging , I have waited for about 10 mins. however the above script is not exectued.

So pressed "ctrl + c" , now I got follwoing output.

(Interrupt -- one more to kill letter)


Then again I pressed "ctrl + c" , now I got the prompt.

#


How to resolve.

James R. Ferguson
Acclaimed Contributor

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Hi (again):

> Now it is hanging , I have waited for about 10 mins. however the above script is not exectued.

You need to provide an some input (even if this input is "empty".

You could do:

# [ -z "${RESULTS}" ] || mailx -r abc@company.com -s "$HOST Filesystems > 90%" abc@company.com < /dev/null

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor
Solution

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

>JRF: You need to provide an some input (even if this input is "empty".

Right. You can also echo $RESULT or read from some file:
[ -z "${RESULTS}" ] || echo "$RESULT" | mailx -r abc@company.com -s "$HOST Filesystems > 90%" abc@company.com
Steven E. Protter
Exalted Contributor

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Shalom,

I like the concept for detecting the file systems above 90%. Note that if you have openview ITO, you can get this functionality without a script.

You might try putting your output to a file and using http://hpux.ws/mailfile2 to email the output as an attachment.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Rita C Workman
Honored Contributor

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

..Didn't Measureware have something in a simple file that one could set these limits on../var/opt/perf/alarmdef

If memory serves me, you could set to notify for CPU,swap,disk I/O, and Filesystem utilization. Maybe, you could just add a line (under red alert) that sends an email when it hits red.

Just a thought,
Rita
Ishwar_1
Frequent Advisor

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

This script will check for all the filesystem with Size more then 90% and mail to the Person.

#-----------Variables
RD1=/tmp/script/check.log

#-----------Truncate
cat /dev/null > $RD1

#------------Logic
df -h | grep dev | awk '{if($5 > 90)print $5, " ", $6}' > $RD1

exec < $RD1
i=0
while read line
do
x=`cat check.log | awk '{print $1}'`
if [ "$x" > 90 ]
then
mailx # Email ID of the Person and File name $RD1
fi
i=`expr $i + 1`
done

Regards
Ishwar
James R. Ferguson
Acclaimed Contributor

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Hi (again):

Bill Hassell offers a nice filesystem monitoring script with notifications here:

http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1130400

See his commentary and attachment in the thread above.

Regards!

...JRF...
Mohandass
Occasional Visitor

Re: How to configure one script to send mail alerts if filesystem is reaching 90%


Hi Senthil,

Below is a part of my script that monitor filesystem. Hope it helps.

df -l |awk '{print $1}' > /tmp/mountlist

cat /tmp/mountlist | while read LINE
do
PERC=`df -k ${LINE} | grep allocation| awk '{print $1}'`


if [ $PERC -gt 95 ]; then

if [ $PERC -gt 98 ]; then
echo "CRITICAL ${PERC}%" | mailx -s "CRITICAL: ${LINE} on `hostname` is almost full ${PERC}%" ${SYSADM2}
else
echo "WARNING ${PERC}%" | mailx -s "WARNING: ${LINE} on `hostname` is almost full ${PERC}%" ${SYSADM2}
fi

fi

Regards
Mohan
senthil_kumar_2
Regular Advisor

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Hi All,

I have changed my script as follows.

#!/bin/sh
RESULTS=$(bdf | awk 'z[split($5,z,"%")-1]>90' | grep -v Filesystem)
[ -z "${RESULTS}" ] || echo "$RESULTS" | mailx -r abc@company.com -s "$HOST Filesystems > 90%" abc@company.com


Now it working fine.


Thanks a lot for all.
senthil_kumar_2
Regular Advisor

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Please see my reply in above