How to execute recurring Bash script at specific times?
at
is excellent tool for one-off commands. To run a program repetitively at the same times, however, the right tool is cron
. Run crontab -e
. It will open an editor. Add this line and save the file:
50 11 * * 2,4 /path/to/script
This will run /path/to/script
every Tuesday and Thursday at 11:50am. crontab
runs programs in a limited environment. So, script
may need to set its own PATH
, etc.
If the machine has a properly set up mail server, any output from script
will be e-mailed to the user who owns the crontab
file. Alternatively, output will be mailed to the address specified by the MAILTO variable in the crontab file. See man 5 crontab
for details.
The first five columns of the line above define the time that the program is run. Their meaning is documented in man 5 crontab
to be:
field allowed values ----- -------------- minute 0-59 hour 0-23 day of month 1-31 month 1-12 (or names, see below) day of week 0-7 (0 or 7 is Sun, or use names)
Related videos on Youtube
Shane
Updated on September 18, 2022Comments
-
Shane almost 2 years
How would I set a script to execute on every Tuesday and Thursday at 11:50am?
I've been looking at the
at
command, but I can't conceive how to use it the way I need to from itsman
page.-
jasonwryan over 9 yearsDepending on your intit system, you could also use a
systemd.timer
...
-