delete old print jobs

Kurt Pfeifle kurt.pfeifle at infotec.com
Thu Jun 28 09:50:06 PDT 2007


> >
> >
> > > I'm afraid, I can't right now re-call or find some old link to a cool
> > > article which showed how to use some commandline params to tell "date"
> > > to show the date of N days ago.
> >
> > Aahhh.... found it. With GNU date, you can use it in the form
> >
> >    date -d "DATESTRING"
> >
> > where DATESTRING may be things like:
> >
> >   yesterday
> >   tomorrow
> >   1 day ago
> >   3 month ago
> >   3 months ago
> >   4 year ago
> >   5 years 8 months 7 days 12 hours ago
> >
> > That means you can do this to print the date 5 days ago:
> >
> >   date -d "5 days ago"
> >
> > But you don't want the timezone info, right? OK then:
> >
> >   date -d "5 days ago" "+%a %d %Y"
> >
> > Now for the full command:
> >
> >   lpstat -o \
> >   |egrep -v "($(date -d "5 days ago")\
> >              |$(date -d "4 days ago")\
> >              |$(date -d "3 days ago")\
> >              |$(date -d "2 days ago")\
> >              |$(date -d "1 days ago"))" \
> >   |while read job_id restofline; do sudo cancel $job_id; done
>
> I just finally got back to this project and saw your post.  For anyone else who may find this useful, here's the script I wrote:
>
> #!/bin/sh
> # This script deletes jobs from print queue from 5-30 days old
>
> x="5"
> while [ $x -lt 30 ]; do
>     lpstat -o|egrep "($(date -d "$x days ago" "+%d %b %Y"))"|
>         while read job_id restofline; do
>             cancel $job_id
>             echo "$(date) Deleted job id: $job_id" >> /var/log/cups/cleanqueue_log
>         done
>     x=$[$x+1]
> done
>
>
> Thank you for all your help.


't was a pleasure  :-)

--
Kurt Pfeifle
System & Network Printing Consultant --- Linux/Unix/Windows/Samba/CUPS
Infotec Deutschland GmbH - A RICOH Company ......... Stuttgart/Germany







More information about the cups mailing list