linux crontab命令用法
2016-07-11 19:12
549 查看
crontab命令是linux提供的配置定时任务的工具
crontab -l:查看现有定时任务
crontab -e:编辑定时任务
分 时 日 月 周 命令
第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 * * * *,表示每十分钟执行一次
/etc/cron.allow 文件存在,那么只有这个文件中列出的用户可以使用 crontab, 同时 /etc/cron.deny文件被忽略;
/etc/cron.allow 文件不存在,那么文件 /cron.deny 中列出的用户
将不能用使用 crontab
下面这种情况用户lxm没有crontab权限
将用户加入cron.allow后,用户lxm有了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
将用户加入cron.allow后,用户lxm有了crontab权限
[root@localhost etc]# cat /etc/cron.allow lxm [lxm@localhost ~]$ crontab -l no crontab for lxm
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 ]
crontab用户存放目录/var/spool/cron
[root@localhost etc]# ll /var/spool/cron total 4 -rw-------. 1 lxm lxm 72 Jul 11 18:54 lxm
相关文章推荐
- Linux socket 初步
- Linux Kernel 4.0 RC5 发布!
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程
- Linux 下无损图片压缩小工具介绍