I want to start command called foo, and kill it if still running after given DURATION in seconds. How do I run a command a time Limit on Linux? How do I run a Linux command, and have it timeout (abort) after N seconds? Can you give timeout command examples in Linux?
GNU/Linux comes timeout command. It runs a command with a time limit. One can also use Perl or bash shell to run a command and have it timeout after N seconds. This page explains how to start a command, and kill it if the specified timeout expires. In other words, run a Linux or Unix command with bounded time.
ADVERTISEMENTS
Our goal is to run a command named “ping www.cyberciti.biz” with a time limit of 30 seconds:
Let us see all timeout commands, syntax and examples in Linux operating systems.
The syntax is as follows for timeout command:
timeout DURATION COMMAND
timeout DURATION COMMAND arg1 arg2
timeout 1m ping google.com
timeout 30s tracepath www.cyberciti.biz
timeout [options] DURATION COMMAND arg1 arg2
DURATION is a floating point number with an optional suffix as follows:
Try:
date
timeout 8s ping www.cyberciti.biz
timeout 8s ping 192.168.2.254
date
Say you want to start ssh session just for fire mintues for running command/app1 and die after 5 minutes, run:
timeout 5m monitor@server1.cyberciti.biz -- /path/to/app1 --save --force --update
#linux