You can use Crontab to schedule the execution of tasks. The command crontab -l
list all the scripts already scheduled on your machine and the option -e
runs the editing mode.
The basic format string looks like this:
Where
A = minutes (0-59)
B = hours (0-23)
C = day (1-31)
D = month (1-12)
E = week day (0-6 where 0 is Sunday)
The following are examples for:
– Execute /bin/do_something.sh at 9:40 PM from monday to wednesday
– Execute the script every 15 minute and every day
– Execute the script every 21st and 44th minute on every hour and every day, but only in December
*\15 * * * * /bin/do_something.sh
21,44 * * 12 * /bin/do_something.sh
Other interesting options:
@reboot = Run once, at startup
@yearly = Run once a year. Like “0 0 1 1 *”
@annually (same as @yearly)
@monthly = Run once a month. Like “0 0 1 * *”
@weekly = Run once a week. Like “0 0 * * 0”
@daily = Run once a day. Like “0 0 * * *”
@midnight (same as @daily)
@hourly = Run once every hour. Like “0 * * * *”
This execute /bin/do_something.sh once, at startup:
How can you manipulate the output?
By default the output is sending to the user (root) mailbox, but it can be redirected.
This Add a row to the file do_something.log inserting output and errors:
Send a mail to me@mydomain.com:
Trash all output: