Enable/Disable printer queue from command line
Sean McBrien
smcbrien at bfsec.bt.co.uk
Fri Jun 16 03:56:33 PDT 2006
haha, thats what I meant.
Well I researched and came up with the perl Expect module and created the following script:
#! /bin/perl -w
use Expect;
my $exp = new Expect;
@printers = ('printera', 'printerb', 'printerc', 'printerd');
$enable = '/usr/bin/enable';
$accept = '/usr/sbin/accept';
$psPrompt = 'Password for root on hostname';
foreach $printer (@printers)
{
$printStatus = `lpstat -p $printer`;
@printStatus2 = split(/ /, $printStatus);
foreach $findProb (@printStatus2)
{
if ($findProb =~ m/Paused/)
{
print "The Printer $printer is paused\n";
$exp->spawn("$enable $printer") or die "Cannot spawn $enable for $printer: $!\n";
sendPass();
}
elsif ($findProb =~ m/Rejecting/)
{
print "The Printer queue for $printer is rejecting jobs\n";
$exp->spawn("$accept $printer") or die "Cannot spawn accept for $printer: $!\n";
sendPass();
}
}
}
sub sendPass
{
$exp->expect(30, $psPrompt );
$exp->send("password\n");
$exp->interact();
}
Its not fully developed but for people who may want to do the same thing as me then work away.
More information about the cups
mailing list