You can use the timeout command that Runs a specified command with a time limit. If the command doesn't complete within the given time, timeout terminates it. For example, run a command named “ping www.cyberciti.biz” with a time limit of 30 seconds:
timeout 30s ping www.cyberciti.biz
See https://www.cyberciti.biz/faq/linux-run-a-command-with-a-time-limit/ for more information. #linux #opensource