From: brian irvin (brian944us@yahoo.com)
Date: Thu Mar 31 2005 - 14:59:03 EST
Thanks to Bill Hassell, Breet geer and Richard wright
all who gave very useful tips.
Question:I need to write a script, which captures all
the print
jobs older than 7 days and send a mail alert to the
admin.
Answers:
Bill:
Since a the print jobs are in the same directory
structure,
just use find -mtime +7 to locate the jobs. Something
like
this:
find /var/spool/lp/request -name 'dA*' -type f -mtime
+7
The result from this search wil return all files that
have
not been printed in the last 7 days. To mail the
results
there are files located:
#!/usr/bin/sh
set -u
export PATH=/usr/bin
MYFILES=$(find /var/spool/lp/request -name 'dA*' -type
f -mtime +7)
[ -n "$MYFILE" ] && echo "$MYFILE" \
| mailx -s "Spool files > 7 days old"
sysadmin@yourcompany.com
Just store the above in a file, add it to cron and run
it once
a day, perhaps early in the morning.
-- Bill Hassell ------------------------------------------------------- Here is a script that does almost exactly what you want. It will warm about print jobs over one day old and delete print jobs over a week old. ========================================= #!/bin/sh # * lpdelete - Remove old files from spool queue and notify * # # * USAGE: lpdelete.sh # # This script will run "lpstat" command and look at all entries. # An email will be sent to "LP_mail" with a warning for every file # over one day old. For every file over 7 days old, the print job # will be canceled. These will be listed in the message as well. # # * END PR=$(basename $0) tmp=/tmp/${PR}.$$ # # to see who "LP_mail" is, look at /etc/mail/aliases and view the "include file" # TOADDR=LP_mail # if ctrl-c then remove the tmp file trap 'INTERPT' SIGINT INTERPT () { rm $tmp exit } HOST=$(hostname) ERROR=0 # # set DDCHK1 ... DDCHKn to days that are to be skipped # in the format of MMM DD # DD=$(date "+%d") MM=$(date "+%m") YY=$(date "+%Y") DD=$(echo $DD | sed 's/^0//') Mon=$(date "+%b") DDCHK1="$Mon $DD " # Function routine to calculate the previous day previous_day () { ((DD = $DD - 1)) if [ $DD -eq 0 ];then ((MM = $MM - 1)) if [ $MM -eq 0 ];then ((YY = $YY - 1)) MM=12 fi DD=$(cal $MM $YY | tail -n2 | head -n1 | awk '{print $NF}') Mon=$(cal $MM $YY | head -n1 | awk '{print $1}' | cut -c1-3) fi } previous_day DDCHK2="$Mon $DD " previous_day DDCHK3="$Mon $DD " previous_day DDCHK4="$Mon $DD " previous_day DDCHK5="$Mon $DD " previous_day DDCHK6="$Mon $DD " previous_day DDCHK7="$Mon $DD " lpstat -o -i | \ # # Following edits will Join two line entry to one line # then eliminate any "on ..." and "copies" text. # Then awk is used to extract the desired fields # sed -n '/^[a-z,A-Z,0-9].*/{ N s/\n/ / p }' | \ sed -e 's/ on [^ ]*//' -e 's/[0-9 ]* copies//' | \ awk '{print $1, $2, $5, $6, $7, $9}' \ > ${tmp} # # If the queue is empty, then put something in for # email message to show. # if [ $(cat ${tmp} | wc -l) -eq 0 ];then echo '-none-' > ${tmp} fi sendmail $TOADDR << __EOF__ Subject: print failure report for $HOST SendTo: $TOADDR DisplayFrom: "$HOST $PR results" The following print jobs are more than one day old. The printer may require attention for supplies or jams. $(grep -v "$DDCHK1" ${tmp}) The following print jobs are more than seven days old and have been deleted. $(grep -E -v "($DDCHK1|$DDCHK2|$DDCHK3|$DDCHK4|$DDCHK5|$DDCHK6|$DDCHK7)" ${tmp}) The following printers are disabled $(lpstat -p | grep disabled) __EOF__ while read JB TO MM DD TI SZ do /usr/bin/cancel $JB done << __EOF2__ $(grep -E -v "($DDCHK1|$DDCHK2|$DDCHK3|$DDCHK4|$DDCHK5|$DDCHK6|$DDCHK7)" ${tmp}) __EOF2__ rm ${tmp} exit ==================================================== Richard Wright Thanks Brian. __________________________________ Do you Yahoo!? Yahoo! Personals - Better first dates. More second dates. http://personals.yahoo.com -- ---> Please post QUESTIONS and SUMMARIES only!! <--- To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl Name: hpux-admin@dutchworks.nl Owner: owner-hpux-admin@dutchworks.nl Archives: ftp.dutchworks.nl:/pub/digests/hpux-admin (FTP, browse only) http://www.dutchworks.nl/htbin/hpsysadmin (Web, browse & search)
This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:46 EDT