delete old print jobs

angelb angelb at bugarin.us
Thu May 17 11:58:45 PDT 2007


> > Is there an easy way to delete print jobs older than a certain date?   I started going down the path of  using lpstat -o |grep -v <date> but ideally I want to delete all jobs older than X days.  We tend to get jobs that sit out there for weeks or longer.  Thanks for any help you can offer.
> >
> > --
> > Amy Tanner
> > amy.tanner at netaspx.com
>
> I had a simillar problem and so I wrote a small script to do the job
> for me. Setup the script in cron and all good to go. Remember to have
> some kind of logrotate going on...the historical file, qremove_log,
> does get large after awhile. Or, if you don't care about the log file,
> take it out of the script. Your PATH and logpath will vary... :)
>
> [code]
> #!/bin/ksh
> #
> # Check for print jobs 14-days or older and remove them
> #
> PATH=/usr/local/bin:/opt/TWWfsw/bin:/usr/bin:/bin
> logpath=/var/opt/TWWfsw/cups124/spool
> alias cancel='$cupspath/cancel'
>
> if [[ -d $logpath ]]
> then
>    # find old jobs and save images
>    #
>    find $logpath/c* -mtime +14 -ls |tee -a /var/log/cups/qremove_log /tmp/qremove.out 2>&1 1>/dev/null
>
>    # remove old jobs
>    #
>    awk '{print $11}' /tmp/qremove.out |awk -F"/" '{print $7}'|cut -c2-10 | xargs -i cancel {} 2>&1 1>/dev/null
>
> else
>    print "Error: Spool directory for CUPS does not exist.\n"
>    exit 1
> fi
>
> # cleanup
> rm /tmp/qremove.out
>
> # eof
> [/code]
>
> btw, the [code] and [/code] is there only to show where the script
> starts and ends... :)

Ok, the above is one way to do it :) but it only deals with jobs that
have been waiting to be printed for more than 14-days. We have so
many printers that some goes offline for so long and goes unoticed and
so my script goes out and check and cancels them.

After rereading your post, you wanted to remove old files...you may use
the script above in conjunction to deleting the actual files if they
are no longer associated with a process.






More information about the cups mailing list