diff options
author | Asbjørn Sloth Tønnesen <asbjorn@asbjorn.biz> | 2017-11-15 20:19:23 +0000 |
---|---|---|
committer | Asbjørn Sloth Tønnesen <asbjorn@asbjorn.biz> | 2017-11-15 20:19:23 +0000 |
commit | 0f9bc9b789055023fbc91d6087f7a1d6901ecd1d (patch) | |
tree | 984d59531690f2946047bcd1d479d6d812b7683b | |
parent | 4d5a6d14940dcb16d7c3615f96b54e495b9b1d06 (diff) | |
download | labitrack-0f9bc9b789055023fbc91d6087f7a1d6901ecd1d.tar.gz labitrack-0f9bc9b789055023fbc91d6087f7a1d6901ecd1d.tar.xz labitrack-0f9bc9b789055023fbc91d6087f7a1d6901ecd1d.zip |
2016: improve printloop (eg. handle offline printer)
Signed-off-by: Asbjørn Sloth Tønnesen <asbjorn@asbjorn.biz>
-rwxr-xr-x | printloop.sh | 7 | ||||
-rwxr-xr-x | trigger.sh | 13 |
2 files changed, 15 insertions, 5 deletions
diff --git a/printloop.sh b/printloop.sh index 64c1e24..26a10f4 100755 --- a/printloop.sh +++ b/printloop.sh @@ -4,12 +4,11 @@ printer="/dev/labelprinter" queuedir=queue print_queue(){ - for job in $(ls -1 "$queuedir/new"); do - ./trigger.sh "$printer" "$queuedir" - done + ./trigger.sh "$printer" "$queuedir" } print_queue -while inotifywait --quiet --timeout 30 "$queuedir/new"; do +while true; do + inotifywait --quiet --timeout 30 "$queuedir/new" print_queue done @@ -6,7 +6,18 @@ printed_dir=$queue_dir/printed/ mkdir -p $printed_dir -for file in $(ls $queue_dir/new/* 2>/dev/null); do +printqueue(){ + ls $queue_dir/new/* 2>/dev/null +} + +queuedepth=$(printqueue | wc -l) + +if [ ! -c "$printer" ] ; then + printf "labelprinter is offline, there are %d jobs in queue\n" $queuedepth >&2 + exit 1 +fi + +for file in $(printqueue); do echo printing $file ./ql570/ql570 $printer $file status=$? |