Reputation: 3325
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!
Upvotes: 10
Views: 10019
Reputation: 7323
Or with crontab -e, or another option, to check the date. for example, if you want to do something every 10 minutes, you can write:
if [ $((`date +%M`%10)) -eq 0 ] && [ `date +%S` -lt 10 ]; then
#your code
fi
Upvotes: 0
Reputation: 246807
You can use at
to reschedule the script from within the script. At the end of the script put:
at now + 10 minutes << END
"$0" "$@"
END
Upvotes: 5
Reputation: 11395
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!
Upvotes: 16
Reputation: 17234
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.
Upvotes: 5