Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash: run a command for n minutes, then SIGHUP it

Tags:

Is there any bash/linux command to launch a long-running command, then kill it after n minutes? I guess I could hack something up with perl using fork and kill, but does anyone know of something already out there?

like image 744
Paul A Jungwirth Avatar asked Dec 12 '10 20:12

Paul A Jungwirth


People also ask

How do I run a command after 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).

How do I run a script every 5 minutes in Linux?

basic 3. /usr/bin/vim. tiny 4. /bin/ed Choose 1-4 [1]: Make a new line at the bottom of this file and insert the following code. Of course, replace our example script with the command or script you wish to execute, but keep the */5 * * * * part as that is what tells cron to execute our job every 5 minutes.

How do I run a script at a specific time in Linux?

From the interactive shell, you can enter the command you want to run at that time. If you want to run multiple commands, press enter after each command and type the command on the new at> prompt. Once you're done entering commands, press Ctrl-D on an empty at> prompt to exit the interactive shell.

What does $() mean in bash?

Again, $() is a command substitution which means that it “reassigns the output of a command or even multiple commands; it literally plugs the command output into another context” (Source).


1 Answers

See the timeout command now in most GNU/Linux distros.

timeout -sHUP 10m command 

The same functionality can be achieved with http://www.pixelbeat.org/scripts/timeout

like image 76
pixelbeat Avatar answered Oct 01 '22 17:10

pixelbeat