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 $?
[root@linux ~]# timeout 3 sleep 2; echo $?
[root@linux ~]#

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