#!/bin/bash # $Header: /home/ACORP/aan/acorpa/live/printjobarchiver.sh,v 1.1 2010/01/14 11:43:13 aan Exp aan $ # $Id: printjobarchiver.sh,v 1.1 2010/01/14 11:43:13 aan Exp aan $ PQ="PRN3 COM6 PTR7 PRA7 PRA6 LPR7 LPR3 PTR1 COM3 PTR2 COM9 PRN6 LPR0 COM0 PRA5" TODAY=`date +%Y%m%d` FULLDATE=`date +%Y%m%d%H%M%S` CUPSDIR=/var/spool/cups PDIR=/home/printhistory PARCHIVE=/home/printarchive CUPSLOGS=/var/log/cups/error_log PLOGS=$PDIR/error_log ALLJOBS=$PDIR/allprintjobs MAILT="aan" FULLCHKQ=`lpstat -o | wc -l` if [ $FULLCHKQ -gt 0 ]; then echo "There are jobs in the live queue, cannot continue. Please wait till jobs have completed them re-run this script manually" | mail -s "ERROR: Could not archive print jobs" $MAILT exit fi #move all printed jobs and removing print reports mv -f $CUPSDIR/d[0-9]* $PDIR/ > /dev/null 2>&1 rm -f $CUPSDIR/c[0-9]* > /dev/null 2>&1 #copy current log file cp -f $CUPSLOGS $PDIR/ #extra information from log files: #print: who,what,where,when cat $PLOGS | grep Job | grep Queued | awk '{print "Job: d"$5" User: " $10 " Queued: " $8 " On: "$2}' | sed 's/]//g' | sed 's/$/]/g' > $ALLJOBS #pipe job number from specfied queue into variable and move into directory of the print queue cd $PDIR for pqueue in $PQ; do ARGS=`cat $ALLJOBS | grep Job | grep Queued | grep $pqueue | awk '{print $2}' | sed 's/$/*/g'` mkdir -p $pqueue/$TODAY mv $ARGS $pqueue/$TODAY/ > /dev/null 2>&1 cat $ALLJOBS | grep $pqueue >> $pqueue/$TODAY/$pqueue done #compress files and remove source #echo "compressing files from printhistory into the printarchive directory" cd $PARCHIVE tar -jcvpf printjobs$FULLDATE.tar.bz $PDIR > /dev/null 2>&1 #echo "remove contents in printhistory directory" rm -rf $PDIR/* #echo "housekeeping on archive directory - removing files older than 60 days" find *.tar.bz -mtime +60 -exec rm -f {} \; echo "Print jobs have been archived successfully!" | mail -s "SUCCESS: Print jobs archived" $MAILT