timeout [option] duration command [ args … ]
Start command
, and kill it if still running after [ duration
.
duration [seconds[s] | minutesm | daysd
--preserve-status
|
If the command times out, and
--preserve-status is not set, then exit with status 124. Otherwise, exit with the status
of COMMAND. If no signal is specified, send the TERM signal upon timeout. The TERM signal kills any process that does
not block or catch that signal. It may be necessary to use the KILL (9) signal, since this signal cannot be caught, in
which case the exit status is 128+9 rather than 124.
BUGS
Some platforms don't currently support timeouts beyond the year 2038.
GNU coreutils online help:
Report any translation bugs to
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:
# timeout bash -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 "