Contact

To run something with a timeout, run the task in background, remembering its PID. Then run another backgrounded subshell that sleeps for the timeout period and then kill the origninal task. The stderr of the kill needs to be sent to /dev/null because it will generate an error if the original command has already finished. The outer shell then has to wait for the original command to return. It will do so either because it finished or because the sleep/kill process killed it after the timeout. By then killing the sleep/kill process you can tell whether the timeout was involed or not.

cmd='command-to-run-with-timeout'
tim='timeout-value-in-seconds'

( $cmd ) &
cmdpid=$!

( sleep $tim; kill $cmdpid 2>/dev/null ) &
timpid=$!

wait $cmdpid

if kill $timpid; then
    echo "$cmd completed normally"
else
    echo "$cmd had to be timed out after $tim seconds"
fi