Skip to content

Instantly share code, notes, and snippets.

@Ry4an
Created May 30, 2013 01:55
Show Gist options
  • Save Ry4an/5675294 to your computer and use it in GitHub Desktop.
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
#!/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