I’m keeping notes in simple text files. Imho, this is a straightforward solution that I can control. I need to be able to version my changes and to keep backup as well. For that, I’m using git. But I have to make commits and push changes periodically. I’m delegating this simple, dull, and repetitive toil to the crontab.
Crontab
..is a file used by cron. It is a time-based job scheduler available in Unix-like OS. It usually looks like this:
SHELL=/bin/bash
MAILTO=root@example.com
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
# execute task at 9:00 and 19:00 every day
0 9,19 * * * /home/me/bin/scripts/task.sh
Every line starting with #
is a comment line. Variables:
- SHELL, specify the shell in which a script will run.
- MAILTO, tells to which email to send job execution result
- PATH, is the path where to look for executable commands
There are other variables available you can check them out in man pages.
Good practice is to set the full path to the command you want to execute. Check as well if it is executable.
To edit crontab
run command: crontab -e
. If the crontab file exists it will be open. If not, an empty crontab file will be created. Then it will be open in your editor. Add at least one line like this one:
0 9,19 * * * /home/me/bin/scripts/task.sh
That would be the minimum required.