timeout [option] duration command [ args … ]
Start command
, and kill it if still running after [ duration
.
duration [seconds[s] | minutesm | daysd
--preserve-status |
duration
is a fixed point number with an optional suffix: s
for seconds (the default),
'm' for minutes, 'h' for
hours or 'd' for days.
If the command times out, and --preserve-status
is not set, exit status 124.
Otherwise, exit with the status of Command
<.
The TERM
kills any process that does not block or catch it.
If the process traps TERM
use the KILL which cannot be caught, in
which case the exit status is 128+9 rather than 124.
Maybe best to use a nested timeoutTERM
outer longer KILL
BUGS
Some platforms don't currently support timeouts beyond the year 2038.
GNU coreutils online help:
Report translation bugs
SEE ALSO
kill(1)
Full documentation
or available locally via: info '(coreutils) timeout invocation'
/usr/bin/timeout
utility is installed by default in most distros which is part of coreutils rpm in Linux
Check if coreutils is installed on your server
# rpm -q coreutils coreutils-8.22-24.el7.x86_64 We can use bash utility with timeout to test SSH connection by checking port 22 status. If you are using a different port for 22 then you can replace it in the below syntax Syntax: # timeoutbash -c "/ " Here server2 is my target host, I will execute the command with a timeout value of 5s on port 22 [root@server1 ~]# timeout 5 bash -c "