Skip to content

Instantly share code, notes, and snippets.

@markus2120
Forked from v6ak/ts-finished
Created January 4, 2020 10:45
Show Gist options
  • Save markus2120/1db2560442d677c3c037877ccd016eea to your computer and use it in GitHub Desktop.
Save markus2120/1db2560442d677c3c037877ccd016eea to your computer and use it in GitHub Desktop.
A handler for Task spooler
#!/bin/bash
# Copyright (C) 2012 Vít Šesták <v6ak.com>
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://www.wtfpl.net/ for more details.
# This utility notifies about completed messages of Task spooler (see http://viric.name/soft/ts/).
# Just add the path to this utility to $TS_ONFINISH.
# This utility is not a part of Task spooler. It is a separate project with a different author.
#
# You may want to add following line to .bashrc:
# export TS_ONFINISH=/usr/bin/ts-finished
jobid="$1"
error="$2"
outfile="$3"
command="$4"
queueSize=$(ts | (read; cat) | grep -vE '^[0-9]+ +finished' | wc -l)
if [ "$error" = 0 ]; then
icon=terminal
else
icon=error
fi
notify-send \
-i "$icon" \
"[TS] finished
[$jobid] $command returned $error
$(tail -n3 "$outfile")
(see $outfile) $queueSize"
if [ "$queueSize" == 1 ]; then # this is the last command in the queue
notify-send \
--icon emblem-default \
-t $((60*60*1000)) \
"[TS] queue empty"
fi
@markus2120
Copy link
Author

Your code is amazing. Thanks.

The following sends email when the task fails.

Newer version of *linux have s-nail or mail instead of sendmail (which is default for task-spooler). Hope someone can find this useful.

#!/bin/bash
# Copyright (C) 2012 Vít Šesták <v6ak.com>
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://www.wtfpl.net/ for more details.

# This utility notifies about completed messages of Task spooler (see http://viric.name/soft/ts/).
# Just add the path to this utility to $TS_ONFINISH.
# This utility is not a part of Task spooler. It is a separate project with a different author.
#
# You may want to add following line to .bashrc:
# export TS_ONFINISH=/usr/bin/ts-finished


jobid="$1"
error="$2"
outfile="$3"
command="$4"

if [ "$error" = 0 ]; then
   icon=terminal
   #notify-send -i $terminal "[TS] finished [$jobid] $command successful" "summary"
else
   #cat $outfile | grep "whatever" | s-nail -s "$(echo -e $command)" user@example.com
   #cat $outfile | grep "whatever" |   mail -s "$(echo -e $command)" user@example.com
fi

exit 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment