Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2720
  • 博文数量: 5
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 60
  • 用 户 组: 普通用户
  • 注册时间: 2018-08-08 21:52
文章分类

全部博文(5)

文章存档

2018年(5)

我的朋友
最近访客

分类: LINUX

2018-08-11 21:25:09

计划任务-002

作者:xzlab

邮箱:xzlab1234@163.com

n周期性计划任务(cron

crontab用于管理计划任务,基于crond.service服务进程

[root@host1 ~]# systemctl status crond

crond.service - Command Scheduler

   Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled)

   Active: active (running) since Fri 2018-08-10 15:28:41 CST; 24h ago

 Main PID: 1391 (crond)

   CGroup: /system.slice/crond.service

           └─1391 /usr/sbin/crond -n

Aug 10 15:28:41 host1 systemd[1]: Started Command Scheduler.

Aug 10 15:28:41 host1 crond[1391]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 31% if used.)

Aug 10 15:28:42 host1 crond[1391]: (CRON) INFO (running with inotify support)


查看帮助

[root@host1 ~]# man 5 crontab


计划任务编写格式:

* * * * * 指令动作,星号依次代表“分钟 小时 日期 星期”

*”表示任意时间

“,”表示不连续时间点

-”表示一个连续时间范围

/”指定间隔的时间频率


0 16 * * 1-6   
周一至周六每天16:00

*/3 * * * * 每隔三分钟


定制的计划任务存放路径

/var/spool/cron/


系统计划任务存放路径

/etc/cron.hourly/

/etc/cron.daily/

/etc/cron.weekly/

/etc/cron.monthly/


限制用户

/etc/cron.deny文件用于限制执行周期性计划任务的用户范围,/etc/cron.deny里包含的用户名将无权限执行周期性计划任务。

[root@host1 ~]# cat /etc/cron.deny

xzlab

[root@host1 ~]# su - xzlab

Last login: Sat Aug 11 16:28:12 CST 2018 on pts/0

[xzlab@host1 ~]$ crontab -e

You (xzlab) are not allowed to use this program (crontab)

See crontab(1) for more information

n命令介绍

编辑当前用户计划任务(-e

每小时的18分,创建file1;每小时的20分,重启系统;

[root@host1 ~]# crontab -e

18 * * * * touch /root/file1

20 * * * * systemctl reboot

编辑指定用户计划任务(-u

[root@host1 ~]# crontab -e -u xzlab

no crontab for xzlab - using an empty one

40 * * * * touch /home/xzlab/test01

查看计划任务(-l

[root@host1 ~]# crontab -l

18 * * * * touch /root/file1

20 * * * * systemctl reboot

删除计划任务(-r

[root@host1 ~]# crontab -u xzlab -r


阅读(195) | 评论(0) | 转发(0) |
0

上一篇:计划任务-001

下一篇:没有了

给主人留下些什么吧!~~