Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash script to run in 5 minutes

Tags:

bash

timed

I just want a bash script to run 5 minutes after it's called. What am I doing wrong?

I have the command:

/path/to/my/script | at now + 5 min

And yet the script runs right away every time.

like image 225
James Nine Avatar asked Oct 18 '10 23:10

James Nine


People also ask

How do I run a shell script every 5 minutes?

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 linux script every minute?

If you want to run a program or script in the background on Linux then cron job is very important. With the help of cron jobs, you can execute a program or script in the background after a given interval of time.

How do I run a linux script in 5 seconds?

What you could do is write a shell script with an infinite loop that runs your task, and then sleeps for 5 seconds. That way your task would be run more or less every 5 seconds, depending on how long the task itself takes. You can create a my-task.sh file with the contents above and run it with sh my-task.sh .


2 Answers

You are executing the script immediately and sending its output into at. You need to send the name of the script itself into at:

echo /path/to/my/script | at now + 5 min
like image 112
Jack Kelly Avatar answered Sep 17 '22 14:09

Jack Kelly


how about:

sleep 300 && /path/to/my/script
like image 44
Amir Afghani Avatar answered Sep 16 '22 14:09

Amir Afghani