new tool: args2env
[hband-tools.git] / user-tools / lpjobs
blob06aea9ec7e297881af873443fec5f7ade57899bb
1 #!/bin/bash
3 true <<'EOF'
4 =pod
6 =head1 NAME
8 lpjobs - Show printer queue jobs (wrapper for lpq and lpstat)
10 =cut
12 EOF
15 TAB=$'\t'
18 LANG=C lpq -a |\
19 sed -e '/^no entries$/ d' |\
20 td-trans-fixcol |\
21 ifne td-select -H Job Rank 'File(s)' |\
23 declare -a job_rank
24 declare -a job_filename
25 declare -a job_printer
26 declare -a job_datetime
27 declare -A jobs
29 while read -r jobid rank filename
31 job_rank[$jobid]=$rank
32 job_filename[$jobid]=$filename
33 jobs[$jobid]=1
34 done
36 LANG=C lpstat -o | td-trans -m 4 |\
37 td-add-headers -X PRINTERJOBID USER SIZE DATETIME |\
38 td-alter _='($printer, $jobid) = PRINTERJOBID =~ /^(.+?)-(\d+)$/' PRINTER='$printer' JOBID='$jobid' |\
39 ifne td-select -H JOBID PRINTER DATETIME |\
41 while read -r jobid printer datetime
43 job_printer[$jobid]=$printer
44 job_datetime[$jobid]=$datetime
45 jobs[$jobid]=1
46 done
48 echo "JOB${TAB}PRINTER${TAB}RANK${TAB}DATETIME${TAB}FILE"
50 for jobid in `printf '%s\n' "${!jobs[@]}" | sort -n`
52 echo "$jobid${TAB}${job_printer[$jobid]}${TAB}${job_rank[$jobid]}${TAB}${job_datetime[$jobid]}${TAB}${job_filename[$jobid]}"
53 done