delete old print jobs
amy.tanner at netaspx.com
Thu Jun 28 09:24:26 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:
> 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:
# This script deletes jobs from print queue from 5-30 days old
while [ $x -lt 30 ]; do
lpstat -o|egrep "($(date -d "$x days ago" "+%d %b %Y"))"|
while read job_id restofline; do
echo "$(date) Deleted job id: $job_id" >> /var/log/cups/cleanqueue_log
Thank you for all your help.
More information about the cups