crontab文件的含義
minute:表示分鍾,可以是從0到59之間的任何整數。
hour:表示小時,可以是從0到23之間的任何整數。
day:表示日期,可以是從1到31之間的任何整數。
month:表示月份,可以是從1到12之間的任何整數。
week:表示星期幾,可以是從0到7之間的任何整數,這里的0或7代表星期日。
備注:最小單位就是分鍾了,如果全是*,就是每分鍾執行一次。
看一下crontab的文件
root@:~# vi /etc/crontab # /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # 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
每天0時0點執行root的執行權限,執行路徑寫腳本的路徑
0 0 * * * root /xxx
每分鍾執行一次操作:
* * * * * root /xxxb
每周一到周五,早上9點執行腳本
0 9 * * 1-5
每12小時執行一遍
0 */12 * * *