Last active
August 29, 2015 14:10
-
-
Save marek-saji/d558f30372dabec955b5 to your computer and use it in GitHub Desktop.
Clean up after script ends (e.g. on ssh timeout)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Clean up after script ends (e.g. on ssh timeout) | |
TIMEOUT=3 | |
HEARTBEAT=$(( TIMEOUT - 2 )) | |
TIMESTAMP_FILE=$( mktemp ) | |
date +%s > ${TIMESTAMP_FILE} | |
nohup bash -c " | |
while sleep ${TIMEOUT} | |
do | |
TIMESTAMP=\$( cat ${TIMESTAMP_FILE} ) | |
NOW=\$( date +%s ) | |
if (( NOW - TIMESTAMP > ${TIMEOUT} )) | |
then | |
notify-send --hint=int:transient:1 -- OHAI | |
break | |
fi | |
done | |
" 2>/dev/null & | |
echo 'Kill me with ^C after some while' | |
while sleep ${HEARTBEAT} | |
do | |
NOW=$( date +%s ) | |
echo $NOW > ${TIMESTAMP_FILE} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment