Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending mail when partition is full 1

Status
Not open for further replies.

Jimbo2112

IS-IT--Management
Mar 18, 2002
109
0
0
GB
Hi All,

I am writing a script to alert me of when the /dmps partition on my server is above 90% full. I need to know the command sequence to get my Unix system to mail a message to my general mail account

e.g. me@my.domain.com

The mail message need only contain the subject matter which is held as a very small text file created from the small script that I have writen so far.

I am sure this is posible but my faithful old Unix in a Nutshell book has left me scratching my head!

Any ideas?

Cheers

Jimbo

 
Look at the script on the unix scripting forum FAQ.
 
Not sure if this helps, but you could just add something like this:

if condition is met
then

cat message.file | mailx youremail@domain.com
 
This is what I use:

EMAIL=`cat /usr/local/cfg/email_bkup.txt`
hostnm=`hostname`

diskstat=`df -k | grep dsk | awk '{t = $2; u = $3; a = $4; p = $6} { if ((u/t*100) > 93) printf("File System FULL Alert: %-15s\t %8d MB Free\t %5.3f%%\n",p,a/1024,(u/t)*100) }'`

if [ "$1" = "mail" ]; then
echo "$hostnm \n$diskstat" | mailx -s "${hostnm} File System ALERT!!" ${EMAIL}
echo "$hostnm \n$diskstat"
else
echo "$hostnm \n$diskstat"
fi

Hope this helps.
 
Thanks all,

I think the crucial thing here is the `mailx` command. I have integrated this into my script and tried it out with a purposely low limit to make the mail send the message. I did this about 10 minutes ago and have not received anything yet.

I am wondering if my system might not be set up to send external mail. How can I check this?

Cheers

Jimbo
 

try this...

df -k | grep -v capacity | while read dsk
do
size=`echo ${dsk} |awk '{print $5}' | sed 's/%//'`

if test ${size} -ge 90
then
mailx -s &quot;FS SIZE LIMIT&quot; yourmail@domain.com <<EOF
echo ${dsk}
EOF
fi
done
 
I use this script is works a treat. Feel free to use and amend. [bigsmile] england for the cup ! [bigsmile]


#!/bin/ksh

#
# Checks for disk usage on file systems and sends result to E-Mail address
# Note - will only work for Sun servers with mail enabled
# Tune the variables below, then run this script from cron or manually.
# May be useful for pre-empting problems on remote support i.e. run a
# cron every night and forewarn.
#
# REPORTTO = set to receiving email address e.g. remote support
# MAXDISKFULL = Warn for any filesystem use beyond this percentage
#
REPORTTO=yourmail@yourdomain.com
MAXDISKFULL=95

PATH=/usr/bin:/usr/sbin:/sbin

TMPFILE=/tmp/output.$$
HOSTNAME=`uname -n`

# be somewhat paranoid about security.
touch $TMPFILE
while [[ -h $TMPFILE ]] ; do rm $TMPFILE; touch $TMPFILE; done

errprint()
{
print $* >>$TMPFILE
}

df -k | awk '
NR==1 {next}
{ split($5,tempval,&quot;%&quot;);
used=tempval[1];
if(int(used)> '$MAXDISKFULL'){
print &quot;space used on &quot; $6 &quot; (&quot; $1 &quot;) is &quot; $5;
}
}
' >>$TMPFILE

##################################################
# And here's the end: Check for error output , and
# email a warning if we find any
#
if [[ -s $TMPFILE ]] ; then
print &quot;&quot; >>$TMPFILE
uname -a >>$TMPFILE
date >>$TMPFILE
print &quot;Generated by $0&quot;
mailx -s &quot;Systems problem on $HOSTNAME&quot; $REPORTTO <$TMPFILE
# more $TMPFILE
fi
rm $TMPFILE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top