- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- A new script is required
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2007 03:39 AM
09-05-2007 03:39 AM
I am being asked if it is possible to script a cron job so that it will check our print queues for jobs that have been sitting idle for 15 minutes.
The script is also required to email the person who submitted the print job. I am currently using /etc/mail/aliases on the local machine.
Any suggestions?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2007 03:53 AM
09-05-2007 03:53 AM
Re: A new script is required
What you could try is the output of lpstat -o and compare it to the output of 15 minutes ago. This isn't foolproof because some printjobs take much longer than 15 minutes to complete. It also makes a difference if these are Network printers, Remote printers, or directly-attached printers. In the case of Network printers, enabling true end of job might appear to be an answer but that will usually create far more problems than it solves. The mailing part is trivially easy as the lpstat -o output has everything you need (except perhaps a UNIX user to mail address lookup but that can be a simple file).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2007 04:22 AM
09-05-2007 04:22 AM
Re: A new script is required
Good point on the idle question.
I would like to do an lpstat -0 every 15 minutes and if the print job was submitted more than 15 minutes ago, to send an email to the submitter: here is an example
istatux /home1/nickd root lpstat -o
kit1-494 root priority 0 Sep 5 11:33
(standard input) 5092 bytes
I sent this job at 11:33 and if I was to have a script that ran now, I would like an email sent to root in this case as root submitted the job.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2007 07:02 AM
09-05-2007 07:02 AM
Solution------------------------------------------
#!/usr/bin/sh
export PATH=${PATH}:/usr/bin
typeset PROG=${0##*/}
typeset TDIR=${TMPDIR:-/var/tmp}
typeset TF1=${TDIR}/X${$}_1.lp
typeset TF2=${TDIR}/X${$}_2.lp
typeset -i DELAY=900 # seconds
typeset -i STAT=0
typeset JOB=""
typeset USER=""
trap 'eval rm -f ${TF1} ${TF2}; exit' 0 1 2 3 15
lpstat -o | awk '{if ($1 ~ "^[A-Za-z0-9].+-[0-9]+$") {print $0}}' > ${TF1}
STAT=${?}
if [[ ${STAT} -ne 0 ]]
then
echo "${PROG}: lpstat failed; status ${STAT}." >&2
fi
while [[ 1 -eq 1 && ${STAT} -eq 0 ]]
do
sleep ${DELAY}
lpstat -o | awk '{if ($1 ~ "^[A-Za-z0-9].+-[0-9]+$") {print $0}}' > ${TF2}
awk '{print $1}' ${TF1} | while read JOB
do
awk -v job="${JOB}" \
'{if ($1 == job) {print $2; exit(0)}}' ${TF2} | while read USER
do
echo "Send mail to ${USER} about printjob ${JOB}"
done
done
mv ${TF2} ${TF1}
STAT=${?}
if [[ ${STAT} -ne 0 ]]
then
echo "${PROG}: mv failed; status ${STAT}." >&2
fi
done
exit ${STAT}
-------------------------------------------
You don't really have to keep up with the times. You simply do an lpstat -o and save the important data to a file, TF1. Wait 15 minutes and do the same operation and capture the lpstat output in TF2. Now read TF1 and see if printername-jobno is still in both files and if so send mail to the user.
Finally mv TF2 to TF1 and repeat. I'll leave the mailing up to you as that part is trivially easy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2007 07:17 AM
09-05-2007 07:17 AM
Re: A new script is required
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2007 04:38 AM
09-10-2007 04:38 AM
Re: A new script is required
The script seems to hang for some reason, not sure why.
Sorry, I am not much of a scripter so I don't even know where to begin to look.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2007 05:16 AM
09-10-2007 05:16 AM
Re: A new script is required
I suspect your production version will be started/stop by an rc script. For testing purposes reduce the DELAY to something like 15 seconds and intentionally disable one of your print queues.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2007 05:37 AM
09-10-2007 05:37 AM
Re: A new script is required
Sorry about that.
Thanks, it works fine.
Thanks Clay.