if ($remove) {
$remove = lc($remove);
my $removeq = $remove;
my %remove_cmd = ( remove => "rmquedev -d $removeq -q $removeq" );
print "Are you sure you want to remove print queue \"$removeq\" [Y/n]?";
$_ = <>;
chomp($_);
$_ = "Y" if ( length($_) == 0 );
if ( $_ =~ /[Yy]/ ) {
# Wait for user-input
system( $remove_cmd {'remove'} );
print
"Prepairing to remove \"$removeq\" from the CC_print.printers file.\n";
sleep 2;
&clean_the_file();
}
else {
die "You chose NOT to remove queue \"$removeq\"\n";
}
}
####
sub clean_the_file {
my $sourcefile = "/u/ccsys/CC_print.printers";
# Keep a dedicated backup of CC_print.printers
if ( !-t "/root/CC_print.printers.bkp" ) {
system("touch /root/CC_print.printers.bkp");
system("cp -R $sourcefile /root/CC_print.printer.bkp");
}
if ( -t "/root/CC_print.printers.bkp" ) {
system("cp -R $sourcefile /root/CC_print.printer.bkp");
# grab the sourcefile and the string to remove as the first and second arguments
my ( $sourcefile, $removeq ) = @_;
# create a temporary file
system("touch /u/ccsys/CC_print.printers.bkp_mkpq");
my $tempfile = "/u/ccsys/CC_print.printers.bkp_mkpq";
# extract lines from $sourcefile which do NOT have the string to remove
# note that the \' inserts ticks so that strings with spaces can work, too
`grep -v $removeq $sourcefile > $tempfile`;
sleep 1;
print "Waiting to unlink..\n";
# delete source file, then rename working file
unlink($sourcefile);
rename( $tempfile, $sourcefile );
system("rm -rf $tempfile");
}
}
####
sub cleanthefile {
my @filehandles;
# Keep varibles in same order as they were passed to the sub-routine
my ( $removeq, $sourcefile, $tempfile, $backup ) = @_;
# Keep a dedicated backup of CC_print.printers
if (-e "$_[3]" ) {
system ( "cp -R $_[1] $_[3]" );
# create a temporary file
if ( !-e "$_[1]") {
system("touch $_[2]");
}
# extract lines from $sourcefile which do NOT have the string to remove
# note that the \' inserts ticks so that strings with spaces can work, too
if ( -e "$_[1]") {
# system ("cat $sourcefile \| grep -v $removeq $sourcefile > $tempfile");
system ( "grep -v $_[0] $_[1] > $_[2]" );
sleep 1;
print "Waiting to unlink..\n";
# delete source file, then rename working file
unlink($_[1]);
rename( $_[2], $_[1] );
system("rm -rf $_[2]");
}
}
else {
system("touch $_[3]");
system("cp -R $_[1] $_[3]");
}
}
####
Command that was run
mkpq -r queue-03