Computing.Net > Forums > Unix > Terminate paging after x number of msgs

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Terminate paging after x number of msgs

Reply to Message Icon

Name: Steve
Date: June 28, 2002 at 15:06:48 Pacific
Comment:

I am developing a script that monitors directory sizes. The script send emails and pages when certain percentage thresholds are reached. My question is: how to implement functionality to stop paging and sending email after 3 times. The script will run via a cron job every 15 mins.

#!/bin/ksh
# This script monitors directory size and emails/pages support personnel when certain threshold sizes are exceeded.

host=`/bin/hostname`
sysdate=`/bin/date`
COM_DIR=/home/commun
PG_SENT_FILE=${COM_DIR}/pg_sent_file
COM_FILE=${COM_DIR}/comm_file
LOG_DIR=/home/logs
LOG=${LOG_DIR}/monitor.log
#var=`df /var | tail -1 | tr -s ' ' ' ' | cut -d' ' -f4 | cut -d'%' -f1`
title1="is > 95%"
title2="is > 90%"
title3="is > 85%"
title4="is > 80%"

#Remove any old temporary files
rm -f ${LOG}*.tmp

#Keep one copy of the previous log file
if [[ -f ${LOG} ]]
then
mv -f ${LOG} ${LOG}.old 2>${LOG}.$$.tmp
if (( $? !=0 ))
then
exit 1
fi
rm -f ${LOG}.$$.tmp
fi

. ${COM_FILE}
. ${PG_SENT_FILE}


function check
{
dir=$1

per=`df -k ${dir} | tail -1 | tr -s ' ' ' ' | cut -d' ' -f4 | cut -d'%' -f1`;

if [ ${per} -ge 95 ]
then
echo "\n**PROBLEM DIRECTORY IS ${dir} **" >> ${LOG}
echo "`df -k ${dir}`" >> ${LOG}
echo "`df -k ${dir}`" | mailx -s "Alert! ${dir} on ${host} ${title1}" "${MAIL_LIST[*]}" "${PIN_LIST[*]}" 2>> ${LOG}
if (( $? !=0 ))
then
exit 1
fi
return 0
fi

if [ ${per} -ge 90 ]
then
echo "\nPROBLEM DIRECTORY IS ${dir} **" >> ${LOG}
echo "`df -k ${dir}`" >> ${LOG}
echo "`df -k ${dir}`" | mailx -s "Alert! ${dir} on ${host} ${title2}" "${MAIL_LIST[*]}" "${PIN_LIST[*]}" 2>> ${LOG}
if (( $? !=0 ))
then
exit 1
fi
return 0
fi

if [ ${per} -ge 85 ]
then
echo "\n**PROBLEM DIRECTORY IS ${dir} **" >> ${LOG}
echo "`df -k ${dir}`" >> ${LOG}
echo "`df -k ${dir}`" | mailx -s "Alert! ${dir} on ${host} ${title3}" "${MAIL_LIST[*]}" 2>> ${LOG}

if (( $? !=0 ))
then
exit 1
fi
return 0
fi

if [ ${per} -ge 80 ]
then
echo "\n**PROBLEM DIRECTORY IS ${dir} **" >> ${LOG}
echo "`df -k ${dir}`" >> ${LOG}
echo "`df -k ${dir}`" | mailx -s "Alert! ${dir} on ${host} ${title4}" "${MAIL_LIST[*]}" 2>> ${LOG}
if (( $? !=0 ))
then
exit 1
fi
return 0
fi
}
status=0
echo "\n ${sysdate}" >> ${LOG}

check "/var";
if (( $? !=0 ))
then ${status}=1
fi

check "/tmp";
if (( $? !=0 ))
then ${status}=1
fi
check "/home";
if (( $? !=0 ))
then ${status}=1
fi
check "/";
if (( $? !=0 ))
then ${status}=1
fi

check "/logs";
if (( $? !=0 ))
then ${status}=1
fi

check "/cddata";
if (( $? !=0 ))
then ${status}=1
fi

check "/production";
if (( $? !=0 ))
then ${status}=1
fi

for i in `ls /logs`
do
check "/logs/$i";
if (( $? !=0 ))
then ${status}=1
fi
done

for j in `ls /cddata`
do
check "/cddata/$j";
if (( $? !=0 ))
then ${status}=1
fi
done

if [ "${status}" = 1 ]
then mailx -s "Error in threshold monitor script" "${MAIL_LIST[*]}"
if (( $? !=0 ))
then
echo "Email notification of script failure unsuccessful-writing to log." >> ${LOG}
fi
fi
exit 0



Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: June 28, 2002 at 16:21:14 Pacific
Reply:


I'd suggest keeping the number of emails/pages sent in a file.

When you run this script, if no page is sent, you write the number zero to the file. If a page is sent, you read the file's current number, increment it and write it back to the file.

A couple of questions to answer:

1-when do I read this number? If I read it and it's already three, do I want to do the check anyway or do I want to just abort the script?

2-once the threshold is reached, then how do I handle things?


You might do something like:

-if a problem is found and count >3 and ((count-3) % 8 != 0) (meaning it's less than two hours since last page), then increment count but don't page

-if a problem is found and count >3 and ((count-3) %8 == 0) (it's been two hours since last page), then increment and page (or maybe page someone else)

Lotsa possibilities


0

Response Number 2
Name: Steve
Date: July 1, 2002 at 06:53:46 Pacific
Reply:

1-Read the number of pages sent already before function check is run. Abort the script if #of pages sent already is 3.

2-Once the threshold is reached email and pages are sent to a list of people.

I'm having the most difficulty with developing the syntax of the code which writes out to a file and increments by 1 each time a threshold is reached.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


unix password reset dual booting windows+unix



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Terminate paging after x number of msgs

Terminal green after X-Windows www.computing.net/answers/unix/terminal-green-after-xwindows/4601.html

Number of child process www.computing.net/answers/unix/number-of-child-process/4029.html

Display number of files on screen www.computing.net/answers/unix/display-number-of-files-on-screen/4100.html