| /etc/cron.allow exists ? | /etc/cron.deny exists ? | who may use crontab ? |
|---|---|---|
| no | whatever |
|
| yes | whatever |
|
making a crontab read-onlyis to :
-rwxr-sr-x 1 root crontab 39K mars 31 2024 /usr/bin/crontab
The syntax of the crontab file was successfully checked. result of crontab -n "$myCrontabFile" : no error found crontab: crontabs/kevin: rename: Operation not permitted result of crontab "$myCrontabFile" : can not overwrite immutable file
does the jobalbeit not being the cleanest one.
You (kevin) are not allowed to use this program (crontab)
See crontab(1) for more information
CRON /var/log/syslog>/dev/null 2>&1.
crontab is used to :
| crontab option | Description |
|---|---|
| -e | edit the crontab with EDITOR |
| -l | list registered jobs (view the crontab) |
| -n | dry-run :
|
| -r | remove the crontab |
| -u kevin |
|
| crontab myFile | register myFile as the new crontab, i.e. overwriting the previous crontab |
crontab works so that you cannot append a new job at the end of a table. Instead, you have to :
key = value form (spaces around the = sign are allowed) but there are limitations : these are not supported :
somePath = $HOME/binA=1 B=2 C=$A $B
PATH = ~/binless -p "PATH is inherited"' 5 crontab)| # | usage | range of values |
|---|---|---|
| 1 | minutes | 0-59 |
| 2 | hours | 0-23 |
| 3 | day of month | 1-31 |
| 4 | month |
|
| 5 | day of week |
|
0 0 23 ? * * *
crontab jobs, these must be understood as
scheduled jobs
seconds (as the 1st field) and year (as the last one)| character | usage | example (more examples below) |
|---|---|---|
* |
|
* * * * * : run every minute of every hour of every day (very common but rarely a good idea IMHO) |
, |
list of values | 0 10,12,16 * * * : run at 10:00, noon and 16:00 |
- |
inclusive range of values |
when using the
x-y rangesyntax, x must be ≤ y |
/n |
do every n intervals |
|
~ |
randomization
|
a random number is picked
|
| string | meaning |
|---|---|
@reboot |
Run once, at startup. |
@yearly@annually |
Run once a year : 0 0 1 1 * |
@monthly |
Run once a month : 0 0 1 * * |
@weekly |
Run once a week : 0 0 * * 0 |
@daily@midnight |
Run once a day : 0 0 * * * |
@hourly |
Run once an hour : 0 * * * * |
@reboot, the startup time is the time when the cron daemon itself started. Due to the boot order sequence of the machine, this _may_ be before some other system daemons (details)0,10,20,30,40,50 * 1,16 * 1-5 /usr/local/bin/command
*/10 * 1,16 * 1-5 /usr/local/bin/command
/n says that within the specific interval (in this case, every minute), run the command every n minutes; in this case, every 10 minutes.20-40 * 1,16 * 1-5 /usr/local/bin/command
20-40/3 * 1,16 * 1-5 /usr/local/bin/command
0-20/2,21-40/3,41-59/5 * 1,16 * 1-5 /usr/local/bin/command
*/2 * * * * jobEven 1-59/2 * * * * jobOdd
jobExecutionMinute % n != 0 ? (source)Instead of :
1,6,11,16,21,26,31,36,41,46,51,56 * * * * /my/script 3,13,23,33,43,53 * * * * /my/other/scriptyou can do :
1-56/5 * * * * /my/script 3-53/10 * * * * /my/other/script
start-stop/increment# 1st monday of month at 6h30
30 6 * * 1 [ $(/bin/date +\%d) -lt 8 ] && /sbin/init 6
# Last wednesday of every month, at 6h30
#30 6 * * 3 [[ $(date +\%d) == $(echo "$(echo "$(cal -s )"|awk '{print $4}')"|tail -1) ]] && /sbin/init 6
# not tested yet