if ($remove) { $remove = lc($remove); my %remove_cmd = ( remove => "rmquedev -d $remove -q $remove" ); print "Are you sure you want to remove print queue \"$remove\" [Y/n]?"; $_ = <>; chomp($_); $_ = "Y" if ( length($_) == 0 ); if ( $_ =~ /[Yy]/ ) { # Wait for user-input system( $remove_cmd {'remove'} ); print "Prepairing to remove \"$remove\" from the CC_print.printers file.\n"; sleep 2; my $removeq = $remove; &cleanthefile($removeq); } else { die "You chose NOT to remove queue \"$remove\"\n"; } } #### sub cleanthefile { my $sourcefile = "/u/ccsys/CC_print.printers"; print $removeq; print "$sourcefile\n"; # Keep a dedicated backup of CC_print.printers if ( -t ne "/root/CC_print.printers.bkp" ) { system("touch /root/CC_print.printers.bkp"); sleep 2; system("cp -R $sourcefile /root/CC_print.printer.bkp"); } if ( -t eq "/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 )= @_; my $tempfile = "/u/ccsys/CC_print.printers.bkp_mkpq"; # create a temporary file if (-e ne "$tempfile") { system("touch /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 if ( -t "$tempfile") { #system ("cat $sourcefile \| grep -v $removeq $sourcefile > $tempfile"); #`grep -v $removeq $sourcefile /dev/null /dev/null > $tempfile`; sleep 1; print "Waiting to unlink..\n"; # delete source file, then rename working file unlink($sourcefile); rename( $tempfile, $sourcefile ); system("rm -rf $tempfile"); } } }