Created
May 30, 2013 01:55
-
-
Save Ry4an/5675294 to your computer and use it in GitHub Desktop.
Write to a named pipe (for ii) but don't block forever doing it
This file contains 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 | |
# adapted from http://stackoverflow.com/questions/422530/write-to-fifo-pipe-from-shell-with-timeout | |
case $# in | |
0) echo "Usage: `basename $0` message..." 1>&2 ;; | |
esac | |
{ | |
echo "$@" > /persistent/dramafever/phenny/irc/irc.freenode.net/#dramafever/in | |
} & | |
waitforpid=$! | |
{ | |
sleep 1 | |
echo "TIMED OUT: $@" 1>&2 | |
2>/dev/null kill -0 $waitforpid && kill -15 $waitforpid | |
} & | |
killerpid=$! | |
>>/dev/null 2>&1 wait $waitforpid | |
# this is the exit value we care about, so save it and use it when we | |
rc=$? | |
# zap our watchdog if it's still there, since we no longer need it | |
2>>/dev/null kill -0 $killerpid && kill -15 $killerpid | |
exit $rc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment