1754018 Members
7666 Online
108811 Solutions
New Discussion юеВ

check lp status

 
SOLVED
Go to solution
Rick Garland
Honored Contributor

check lp status

Hi all:

HPUX 10.20 and 11.00 on K series, L series, and N series.

Trying to develop a script for checking the status of print jobs. What I am looking for is to have a script notify me if there are jobs in the queue that are over 3 hrs old.

Taking a whack at developing a perl script to assist me in doing this but I also am needing the script to display and calculate the time differences.

My whack at the perl script is attached.

Essentially, how can I display the listing in a long format? Doing this will provide the date/time of the files and then how to do the math for the dates that are displayed with the files?

Many thanks!



6 REPLIES 6
harry d brown jr
Honored Contributor

Re: check lp status

Although not in perl, here is a script from the archives of BB:

http://www.deadcat.net/

search for:

chkprt.sh

or attached

live free or die
harry
Live Free or Die
Alan Riggs
Honored Contributor

Re: check lp status

This is just old-fashioned ksh, but it should work. Note: I am cancelling any jobs from a previous day/month. If you want to run this job between midnight and 3AM you will need to modify that logic.

The time manipulations in this assume EST.

MONTH=$(TZ=GMT+8 date +%b)
DAY=$(TZ=GMT+8 date +%d)
HOUR=$(TZ=GMT+8 date +%H)
lpstat -t | grep -| grep -v enabled| while read JOB j1 j2 j3 J_MON J_DAY J_TIME junk
do
J_HOUR=${J_TIME%:*}
if [[ $MONTH != $J_MON || $DAY != $J_DAY || $HOUR -gt $J_HOUR ]]
then
cancel $JOB
fi
done
Rick Garland
Honored Contributor

Re: check lp status

Close, but not quite there.

Not looking to cancel the jobs as this would be up to the client.
Alan Riggs
Honored Contributor

Re: check lp status

Then change "cancel $JOB" to "elm -s "Old print job $JOB on $(hostname)" $USER"

And read in USER instead of j1.

Did I miss anything else?
Marco Paganini
Respected Contributor
Solution

Re: check lp status

Hello Rick!

As I see, you want to see all print jobs older than 3 hours. Is that it? If that's the case, you can test the time stamp on your printer queue control files with perl's 'stat' command and compare them to your localtime. Like this:

$mtime = (stat($filename))[8];
if ((time() - $mtime) > (3*3600)) {
print "file $filename is older than 3 hours\n"
}

Make sure you put this test inside your loop to test every control file on /var/spool/lp/request/printername/c*

Regards,
Paga
Keeping alive, until I die.
A. Clay Stephenson
Acclaimed Contributor

Re: check lp status

Hi Rick:

Here is a 3 minute perl script which should be close. It lists those in the queue over 3 hours old plus a readable date stamp.


Clay
If it ain't broke, I can fix that.