tdothooligan
MIS
Hello all,
So here is a little background information as to my troubles. A previous Unix admin I worked with wrote a script for me to notify me via email if any of the print queues were down on a specific Unix box.
The script works great... it tries to re-enable the queue and emails me the results. Problem is, I get over 150 emails a day and a good 99% of them were all able to successfully reenable all 'downed' queues.
My problem is that my current Unix admin is either swamped with work, or is inept, (I'd vouch for the latter) as my ongoing request for months has been to modify this script to ONLY email me if the re-enable of a particular queue was unsuccessful... I figure it will eliminate about 140 or so of those emails from my inbox.
the script is as follows:
I realise you guys/gals aren't paid to do the unix admin that i work with's job, however, if you could point me in the right direction so I can *try* and edit this myself I would appreciate it. I just wanna rid my inbox of a whole bunch of non-necessary mail.
I have a feeling that it will only be a few simple GREP commands to looks for 'unsuccessful' or something, but i'm not sure how to integrate it.
So here is a little background information as to my troubles. A previous Unix admin I worked with wrote a script for me to notify me via email if any of the print queues were down on a specific Unix box.
The script works great... it tries to re-enable the queue and emails me the results. Problem is, I get over 150 emails a day and a good 99% of them were all able to successfully reenable all 'downed' queues.
My problem is that my current Unix admin is either swamped with work, or is inept, (I'd vouch for the latter) as my ongoing request for months has been to modify this script to ONLY email me if the re-enable of a particular queue was unsuccessful... I figure it will eliminate about 140 or so of those emails from my inbox.
the script is as follows:
Code:
#!/bin/ksh
#-----------------------------------------------------------------------------#
# SCRIPT NAME:
#
# CREATED BY: [edited]
#
# PURPOSE: Check for DOWN print queues
#
# VERSION: 1.00
#
# DEPENDANCIES: None.
#------------------------------------------------------------------------------#
# MODIFICATION HISTORY:
#
# DATE(YYYY-MM-DD) NAME DESCRIPTION
# 2006-08-24 JP Initial
#------------------------------------------------------------------------------#
# VARIABLES:
HOSTNAME=$(uname -n) # <Host Name>
PROG_NAME=$0 # <Program Name>
#------------------------------------------------------------------------------#
# FUNCTIONS:
function readDATA
{
echo $data
QUEUE=`echo $data | awk '{print $1}'`
STATE=`echo $data | awk '{print $3}'`
if [[ $STATE != "DEV_BUSY" ]]
then
enable $QUEUE
if [[ $? = 0 ]]
then
echo "$?"
echo "enable $QUEUE command successful" >> /tmp/lpstat_down.txt.
$TS
else
echo "enable $QUEUE command failed" >> /tmp/lpstat_down.txt.
$TS
fi
fi
}
#------------------------------------------------------------------------------#
#---------------------------------------------------------------------
## Begin script.
TS=`date +"%H%M`
/usr/bin/lpstat -W | grep -E "DOWN|DEV_BUSY" > /tmp/lpstat.out.$TS
SIZE=`ls -l /tmp/lpstat.out.$TS | awk '{print $5}'`
if [[ $SIZE != "0" ]]
then
cp /tmp/lpstat.out.$TS /tmp/lpstat.txt.$TS
banner "printer" issues > /tmp/lpstat_down.txt.$TS
echo "Host ==> $HOSTNAME" >> /tmp/lpstat_down.txt.$TS
echo "GENERATED BY ==> $PROG_NAME" >> /tmp/lpstat_down.txt.$TS
echo "" >> /tmp/lpstat_down.txt.$TS
echo "Queue Dev Status " >> /tmp/lpstat_down.txt.$TS
echo "------- ----- ---------" >> /tmp/lpstat_down.txt.$TS
cat /tmp/lpstat.out.$TS >> /tmp/lpstat_down.txt.$TS
echo "" >> /tmp/lpstat_down.txt.$TS
echo "Will enable DOWNed queues" >> /tmp/lpstat_down.txt.$TS
echo "" >> /tmp/lpstat_down.txt.$TS
while read -r data
do
readDATA
done < /tmp/lpstat.txt.$TS
MAIL_SUBJ='Print Queue(s) Problems'
mail -s "$MAIL_SUBJ" username@domain.com < /tmp/lpstat_down.txt.$TS
fi
rm /tmp/lpstat.out.$TS
rm /tmp/lpstat_down.txt.$TS
rm /tmp/lpstat.txt.$TS
exit
I realise you guys/gals aren't paid to do the unix admin that i work with's job, however, if you could point me in the right direction so I can *try* and edit this myself I would appreciate it. I just wanna rid my inbox of a whole bunch of non-necessary mail.
I have a feeling that it will only be a few simple GREP commands to looks for 'unsuccessful' or something, but i'm not sure how to integrate it.