linux crontab命令用法

crontab -l:查看现有定时任务 
crontab -e:编辑定时任务

格式

*  *  *  *  *  command 
分  时  日  月  周  命令 
第1列表示分钟1~59 每分钟用*或者 */1表示,*/10表示每10分钟 
第2列表示小时1~23(0表示0点) 
第3列表示日期1~31 
第4列表示月份1~12 
第5列标识号星期0~6(0表示星期天) 
第6列要运行的命令

*:(星号)表示所有的值,如 ,* 16 5 6 *,表示6月5日16点到17点之间的每一分钟执行一次 
,:(逗号)表示可选的值,如,3,4,5 16 5 6 *,表示6月5日16点3分,4分,5分各执行一次 
-:(中划线)表示范围,如5-10 16 5 6 *,表示6月5日16点5分到10分,每分钟执行异常 
/:(正斜杠)表示频率,如*/10 * * * *,表示每十分钟执行一次

crontab用户权限问题

Linux 下可以通过创建文件 /etc/cron.allow 或者 /etc/cron.deny 来控制权限: 
/etc/cron.allow 文件存在,那么只有这个文件中列出的用户可以使用 crontab, 同时 /etc/cron.deny文件被忽略; 
/etc/cron.allow 文件不存在,那么文件 /cron.deny 中列出的用户 
将不能用使用 crontab

下面这种情况用户lxm没有crontab权限

[root@localhost etc]# cat /etc/cron.deny
lxm
[root@localhost etc]# cat /etc/cron.allow
[root@localhost etc]# 
[lxm@localhost ~]$ crontab -l
You (lxm) are not allowed to use this program (crontab)
See crontab(1) for more information
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

将用户加入cron.allow后,用户lxm有了crontab权限

[root@localhost etc]# cat /etc/cron.allow
lxm
[lxm@localhost ~]$ crontab -l
no crontab for lxm
 
 
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

crontab服务启动与停止

[root@localhost etc]# service crond status
crond (pid  1343) is running...
[root@localhost etc]# service crond stop
Stopping crond: [  OK  ]
[root@localhost etc]# service crond start
Starting crond: [  OK  ]
[root@localhost etc]# service crond restart
Stopping crond: [  OK  ]
Starting crond: [  OK  ]
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

crontab用户存放目录/var/spool/cron

[root@localhost etc]# ll /var/spool/cron
total 4
-rw-------. 1 lxm lxm 72 Jul 11 18:54 lxm
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值