linux centos 7 定时任务

一.安装 crontabs服务并设置开机自启:

yum install crontabs
systemctl enable crond
systemctl start crond123

二.设置用户自定义定时任务:

vi /etc/crontab

可以看到:

# 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-59) 小时(0-23) 日(1-31) 月(11-12) 星期(0-6,0表示周日) 用户名 要执行的命令1
每隔30分钟root执行一次updatedb命令:

*/30 * * * * root updatedb1

每天早上5点定时重启系统:

0 5 * * * root reboot1

三.保存生效:

#加载任务,使之生效crontab /etc/crontab#查看任务crontab -l

 

posted @ 2018-12-06 16:08  飞翔的贺兰猪  阅读(787)  评论(0编辑  收藏  举报