Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a process with a timeout in Bash? [duplicate]

People also ask

How do you wait 30 seconds in bash?

How to Use the Bash Sleep Command. Sleep is a very versatile command with a very simple syntax. It is as easy as typing sleep N . This will pause your script for N seconds, with N being either a positive integer or a floating point number.

What is double colon in bash?

It's nothing, these colons are part of the command names apparently. You can verify yourself by creating and running a command with : in the name. The shell by default will autoescape them and its all perfectly legal. Follow this answer to receive notifications.

How do I run a bash script every 5 minutes?

Easy Method You can set up a bash script that loops forever executing that command then sleeping for 5 minutes. When you start up your computer press ctrl + alt + t and type amazon-sync then minimize the terminal window. Command will run once every 5 minutes (300 seconds).


Use the timeout command:

timeout 15s command

Note: on some systems you need to install coreutils, on others it's missing or has different command line arguments. See an alternate solution posted by @ArjunShankar . Based on it you can encapsulate that boiler-plate code and create your own portable timeout script or small C app that does the same thing.


Some machines don't have timeout installed/available. In that case, you could background the process; its PID then gets stored as $!; then sleep for the required amount of time, then kill it:

some_command arg1 arg2 &
TASK_PID=$!
sleep 15
kill $TASK_PID

At this URL I find that there are mentioned, more than one solutions to make this happen.