#!/bin/bash # # Copyright (c) 2003 SuSE Linux AG Nuernberg, Germany. # # This file and all modifications and additions to the pristine # package are under the same license as the package itself. # # Warning! This script is very dangerous! This script deletes all # printjobs, regardless if active or waiting or anything else. # This deletion is done UNRECOVERABLE. # # please send bugfixes or comments to feedback@suse.de. # # 1. remove old jobs # ...find all local printers printers=`/usr/bin/lpstat -v | \ /usr/bin/awk '{if ($4 !~ /^ipp:/) {gsub(":$", "", $3); print $3}}'` # ...and cancel the jobs for i in "$printers"; do /usr/bin/cancel -a "$i" done # 2. kill pending processes # ...find process pid of cupsd and remember as parent pid ppid=`/bin/ps -A | awk '/cupsd/{print $1}'` # ...find processes descending from daemon # ...find processes owned by "lp" #list1=`/bin/ps --ppid $ppid | /usr/bin/awk '/[0-9]/{printf "%s ", $1}'` if test $ppid then list1=`ps -eo "%P %p" | /usr/bin/awk '{if ($1 ~ /'$ppid'/) {print $2}}'` else list1='' fi list2=`/bin/ps -A -fl | /usr/bin/awk '{if ($3 ~ "lp") printf "%s ", $4}'` # ...kill them /bin/kill $list1 $list2 >/dev/null 2>&1 /bin/sleep 2 # ...find processes again #list1=`/bin/ps --ppid $ppid | /usr/bin/awk '/[0-9]/{printf "%s ", $1}'` if test $ppid then list1=`ps -eo "%P %p" | /usr/bin/awk '{if ($1 ~ /'$ppid'/) {print $2}}'` else list1='' fi list2=`/bin/ps -A -fl | /usr/bin/awk '{if ($3 ~ "lp") printf "%s ", $4}'` # ...kill them with HUP (hopefully not necessary) /bin/kill -1 $list1 $list2 > /dev/null 2>&1 /bin/sleep 3 # ...find processes again #list1=`/bin/ps --ppid $ppid | /usr/bin/awk '/[0-9]/{printf "%s ", $1}'` if test $ppid then list1=`ps -eo "%P %p" | /usr/bin/awk '{if ($1 ~ /'$ppid'/) {print $2}}'` else list1='' fi list2=`/bin/ps -A -fl | /usr/bin/awk '{if ($3 ~ "lp") printf "%s ", $4}'` # ...kill them finaly with KILL (hopefully not necessary) /bin/kill -9 $list1 $list2 >/dev/null 2>&1 # 3. enable printers again. # ...find disabled printers printers=`lpstat -p | awk '{if ($3 ~ /disabled/) print $2}'` # ...and enable them for i in "$printers"; do /usr/bin/enable "$i" >/dev/null 2>&1 /usr/sbin/accept "$i" >/dev/null 2>&1 done