Printer Job Language Technical Reference Manual
[safeq] / xwc-jobs.pl
index 5245ab2..69c3d72 100755 (executable)
@@ -6,15 +6,26 @@ use Data::Dump qw(dump);
 
 my $ip = shift @ARGV || '10.60.3.35';
 my $debug = $ENV{DEBUG} || 0;
-
+my $sep = $ENV{SEP} || "\t";
 
 my $op = shift @ARGV || 'list';
 
 my $url = 'jblist.htm';
-if ( $op eq 'list' ) {
+if ( $op =~ m/^l/i ) { # list
        $url = 'jblist.htm';
-} elsif ( $op eq 'hist' ) {
+} elsif ( $op =~ m/^h/i ) { # history
        $url = 'jbhist.htm';
+} elsif ( $op =~ m/^(d|c)/i ) { # delete/cancel
+       my $job_id = join('/', @ARGV) || die "expected job_id(s) missing";
+       open(my $curl, '-|', "curl --silent -XPOST -d OPR=CANCEL -d JOBS=$job_id/ http://$ip/JOBCTRL.cmd");
+       while (<$curl>) {
+               if ( m/<title>/i ) {
+                       chomp;
+                       s/<[^>]*>//g;
+                       print join($sep, $ip, $job_id, 'CANCEL', $_),"\n";
+               }
+       }
+       exit 0;
 } else {
        die "UNKNOWN op [$op]\n";
 }
@@ -37,7 +48,7 @@ my @headers = @{ $info->{hdrs} };
 unshift @headers, 'id' if $op eq 'list';
 unshift @headers, 'IP';
 
-print join("\t", @headers),"\n";
+print join($sep, @headers),"\n";
 
 foreach my $l ( @{ $info->{info} } ) {
        warn "## l=",dump($l) if $debug > 1;
@@ -45,7 +56,7 @@ foreach my $l ( @{ $info->{info} } ) {
        $l->[3] .= ':' . $info->{stats}->[ $l->[3] ];
        $l->[4] .= ':' . $info->{types}->[ $l->[4] ];
 
-       print join("\t", $ip, @$l), "\n";
+       print join($sep, $ip, @$l), "\n";
 }
 
 foreach my $l ( @{ $info->{jHst} } ) {
@@ -54,5 +65,5 @@ foreach my $l ( @{ $info->{jHst} } ) {
        $l->[2] .= ':' . $info->{stsAry}->[ $l->[2] ];
        $l->[3] .= ':' . $info->{types}->[ $l->[3] ];
 
-       print join("\t", $ip, @$l),"\n";
+       print join($sep, $ip, @$l),"\n";
 }