linux-crond_计划任务

定时计划任务

  主要文件介绍:

[root@nginx ~]# ll /etc/cron* -d
drwxr-xr-x. 2 root root  21 7月  11 20:28 /etc/cron.d
drwxr-xr-x. 2 root root  42 7月   5 05:16 /etc/cron.daily  #系统每天执行定时任务
-rw-------. 1 root root   0 11月 20 2018 /etc/cron.deny   #黑名单
drwxr-xr-x. 2 root root  22 7月  11 20:28 /etc/cron.hourly  #系统每小时
drwxr-xr-x. 2 root root   6 6月  10 2014 /etc/cron.monthly  #系统每个月
-rw-r--r--. 1 root root 451 6月  10 2014 /etc/crontab  #定时任务的主配置文件
drwxr-xr-x. 2 root root   6 6月  10 2014 /etc/cron.weekly  #系统每周

  定时任务存放路径 

[root@nginx cron]# pwd
/var/spool/cron

  定时任务日志

[root@nginx cron]# ll /var/log/cron
-rw------- 1 root root 6744 8月  21 20:32 /var/log/cron

  定时计划任务配置文件参数介绍

[root@nginx cron]# cat /etc/crontab 
SHELL=/bin/bash  #定时任务的命令解释器
PATH=/sbin:/bin:/usr/sbin:/usr/bin  #命令的环境变量
MAILTO=root  #接收邮件的用户

  

  crontab定时任务命令主要参数:

    -e  #编辑定时任务

    -l  #查看定时任务

    -r  #删除定时任务文件

    -u  #指定用户,默认是当前用


举例:(每分钟定时执行同步系统时间)

安装软件:

[root@nginx ~]# yum -y install ntpdate

手动测试命令是否可以同步时间

[root@nginx ~]# ntpdate ntp.aliyun.com
21 Aug 20:43:58 ntpdate[1930]: adjust time server 203.107.6.88 offset -0.002605 sec

编写定时任务

[root@nginx cron]# crontab -e
* * * * * ntpdate ntp.aliyun.com
Aug 21 20:50:01 nginx CROND[2257]: (root) CMD (ntpdate ntp.aliyun.com)
Aug 21 20:51:01 nginx CROND[2311]: (root) CMD (ntpdate ntp.aliyun.com)

定时任务存放路径

[root@nginx cron]# pwd  #文件以用户名命名
/var/spool/cron

猜你喜欢

转载自www.cnblogs.com/yangzhaon/p/11391337.html