Unfortunately the "timeout" command does not exist on mac OS X.
(sleep 2;echo 'done') & sleep 1; kill $! 2> /dev/null || :
(sleep 2;echo 'done') & sleep 3; kill $! 2> /dev/null || :
will not display "done" because the first command executed in less than 3 second.
Walking through this code:
sleep 2;echo 'done': replace this with whatever command you want to keep in check.
sleep 3: replace 3 with whatever max number of seconds you want.
kill $!: kills your prcess after a set number of seconds
2> /dev/null: ignores errors thrown by kill when your command has executed in less than the set number of seconds.
|| :: ignores the "fail" exit code when your code executes in less than the set number of seconds. This is useful if you are running this command in Jenkins for example and you don't want jenkins to set your build to fail when things go well.