#! /bin/sh # # http://sbl.salk.edu/lb/doc/UNIX_CD/upt/ch38_11.htm # # watchq - "daemon" script that watches printer queue(s) for errors temp=/tmp/WATCHQ$$ # Holds output of lpq watch=/usr/local/lib/watchqs # Queue names to watch writeto=lisa # User who gets notices about printer queues="`cat $watch`" # Put list of queue names in $queues trap 'queues="`cat $watch`"' 1 # Reset $queues if we get a SIGHUP trap 'rm -f $temp; exit' 0 15 # Clean up temp file when killed # Loop forever (until someone kills script): while : do for queue in $queues do lpq -P$queue >$temp if egrep '(out of paper|error|warning)' $temp >/dev/null then echo "PRINTER QUEUE $queue:" | cat - $temp | write $writeto fi done sleep 30 done # # End of file #!/bin/ksh # # stop start the daemon script ( nohup ) # ---------------------------- # case "$1" in 'start') nohup /path-to/mydeamonscript >> /path-to/mylogfile 2>&1& ;; 'stop') pid=`ps -ef | grep mydeamonscript | grep -v grep | awk '{print $2} ' ` if test "$pid" ; then /usr/bin/kill $pid else echo "No PID file. Process may not be running" fi ;; *) echo "Usage: $0 { start | stop }" ;; esac exit 0 # # End of file