cron 是三个 Linux
下的按时试行工具,能够在无需人工干预的场合下运作作业。守护进程 cron
会读取 crontab 文件,依照安顿在钦赐的光阴实践任务。
contab 命令用来丰盛、删除、展现 cron 职责表。
(Ubuntu 景况)能够由此 service 命令启动与停止 cron 服务:
service cron status # 查看 cron 服务处境
service cron start # 启动 cron 服务
service cron stop # 停止 cron 服务
service cron restart # 重启 cron 服务
service cron reload # 重新加载 cron 服务配置
crontab [-u user] file
crontab [-u user] [-l | -r | -e] [-i] [-s]
-u
钦定客户
-l
展现当前的 crontab 文件内容。
-r
删除当前的 crontab 文件内容。
-e
编辑当前的 crontab 文件内容,要是文件不设有则开改善文件。
-i
在剔除 crontab 文件内容时予以提示。
格式:minute hour day_of_month month day_of_week command
字段含义
字段
含义
minute
分钟,取值范围是 (0 – 59State of Qatar
hour
小时,取值范围是 (0 – 23State of Qatar
day_of_month
日期,取值范围是 (0 – 31卡塔尔
month
月份,取值范围是 (1 – 12卡塔尔国,也能够用 jan,feb,mar,apr… 表示
day_of_week
星期,取值范围是 (0 – 6卡塔尔(قطر,个中周六用 0 或 7 表示,也足以用
sun,mon,tue,wed,thu,fri,sat 表示
command
要执行的吩咐
特殊符号含义
特殊符号
说明
*
通配全数相当大希望的取值
,
钦命取值列表,举例 1,3,5,7,9
–
钦命整数限量,比方 1-5
/
钦定间距频率
cron 表明式例子
示例
说明
*/15 * * * *
每间距 15 分钟施行职分
0 */2 * * *
每间距 2 个小时,在整点的时候施行职分
0 3 * * * *
每日午夜三点的时候推行职务
0 0 5,15,25 * *
每月 5 号,15 号,25 号早上的时候实施职责
15 12 * * 1
周周生机勃勃早上 12 点 15 分的时候实行任务
0,30 12-20 * * *
每一日 12:00 至 20:59 之间,在整点或有限的时候施行职责
a) 添加 cron 任务
[email protected]:~/huey/linux/cmdline$ echo "*/3 * * * * date >> ~/huey/linux/cmdline/cron.out" > mycron
[email protected]:~/huey/linux/cmdline$ crontab mycron
b) 删除 cron 任务
[email protected]:~/huey/linux/cmdline$ crontab -r
c) 显示 cron 任务
[email protected]:~/huey/linux/cmdline$ crontab -l
*/3 * * * * date >> ~/huey/linux/cmdline/cron.out
命令,linux命令 cron 是一个 Linux
下的定期试行工具,能够在不必要人工干预的情形下运营作业。守护进程 cron
会读取 crontab 文件,根据配…