run commands with timeout

Sometimes you might have use cases, when specific command or script should be run no longer than given amount of time. In those cases you can easily control it by using command “timeout”.

This command will allow you to terminate command if it reaches given time limit, e.g.:

[root@linux ~]# timeout 3 sleep 4; echo $?
124
[root@linux ~]# timeout 3 sleep 2; echo $?
0
[root@linux ~]#

Just add “timeout X” in front of any further command and you are good to go!