Mercurial > hg > aboriginal
diff sources/timeout.sh @ 843:2ca7ea5d3ec1
New native-static-build.sh to compile static dropbear, strace, and busybox inside the emulator and export 'em out via ftp.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 11 Oct 2009 01:56:04 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sources/timeout.sh Sun Oct 11 01:56:04 2009 -0500 @@ -0,0 +1,20 @@ +#!/bin/bash + +# Run a command line with a hang timeout, which kills the child process if it +# doesn't produce a new line of output for $1 seconds. + +# This script has to be a separate process (rather than just a shell function) +# so killing it doesn't kill the parent process. + +source sources/functions.sh + +if [ $# -lt 1 ] +then + echo "Need timeout value" >&2 + exit 1 +fi + +trap "killtree $$" EXIT +TIMEOUT="$1" +shift +( "$@" ) | tee >(while read -t "$TIMEOUT" -n 32 i; do true; done; sleep 1; kill -TERM $$ 2>/dev/null )