Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Last active December 14, 2015 17:26
Show Gist options
  • Save coderofsalvation/2b1f520bc1a260e9ec61 to your computer and use it in GitHub Desktop.
Save coderofsalvation/2b1f520bc1a260e9ec61 to your computer and use it in GitHub Desktop.
flexible desktop notifications using crontab bashscript which uses tail -f on logfiles using ssh
#!/bin/bash
usage='Usage: ssh-tailf-notify <user@server> <logfile> [grep args]
Easy way to receive desktop notifications based on remote logfile-events or named pipes
examples crontab:
* * * * * nohup /home/you/bin/ssh-tailf-notify [email protected] /home/you/irclogs/fnotify.txt -vE "(foo|bar)" &
* * * * * nohup /home/you/bin/ssh-tailf-notify [email protected] /home/sqz/irclogs/EFnet/#python.log -vE "(mynick)" &
* * * * * nohup /home/you/bin/ssh-tailf-notify [email protected] /var/log/messages "-E (memory|booking)" &
* * * * * CMD="cat" nohup /home/you/bin/ssh-tailf-notify [email protected] /home/you/pipe.fifo &
hints:
1) make sure you have passwordless access to the server where irsii is running (ssh-keygen & ssh-copy-id)
2) type in irssi: /set autolog on and/or use fnotify.pl to log /hilight words to ~/irclogs/fnotify.txt
'
[[ ! -n "$2" ]] && { echo "$usage"; exit 1; }
IRSSISERVER="$1"; LOGFILE="$2"; LOCKFILE="/tmp/.lock-$(basename $0)${LOGFILE//\//-}";
shift;shift; GREPARGS="$*"
[[ ! -n $CMD ]] && CMD="tail -n1" # can be overruled
exec /usr/bin/flock -w 0 "$LOCKFILE" ssh -t $IRSSISERVER ${CMD} $LOGFILE | while read msg; do
[[ -n $GREPARGS ]] && { echo "$msg" | grep ${GREPARGS} &>/dev/null || continue; }
gsettings set com.canonical.notify-osd gravity 2 # position box
gsettings set com.canonical.notify-osd multihead-mode focus-follow # show on dual monitors
killall /usr/lib/notify-osd/notify-osd; # clear buffer
DISPLAY=:0.0 notify-send -t 2000 -c irc "$msg"; # display
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment