Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script repeat itself after X minutes

Tags:

bash

loops

I have a bash script in Ubuntu, I want it to run every 10 minutes for example after it's done. How can I do this? Thanks!

like image 583
Aaron Avatar asked Oct 24 '11 08:10

Aaron


People also ask

How do I stop a loop script?

In Bash scripting, a break statement helps provide control inside loop statements. Instead of waiting until the end condition, a break statement helps exit from a loop before the end condition happens.

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

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. Exit this file and save changes.


2 Answers

You can check watch.
From the man pages of watch the description says watch - execute a program periodically, showing output fullscreen, you can try watch -n 600 my_script.sh which will execute myscript.sh every 600 seconds i.e. 10 minutes. watch shows the output to full screen, you can redirect it to say /dev/null in case you are not interested in the output to the screen.
Hope this helps!

like image 101
another.anon.coward Avatar answered Oct 20 '22 14:10

another.anon.coward


Cronjobs is what you need.

My blog post:- http://linux-junky.blogspot.com/2010/10/guide-to-add-cronjob-simplified.html

Or you can also use sleep 600 in your script.

like image 27
Abhijeet Rastogi Avatar answered Oct 20 '22 12:10

Abhijeet Rastogi