每周周天晚上linux计划任务表达式,计划任务cron

本文将要为您介绍的是计划任务cron,具体实现方法:cron 计划任务

作用: 计划任务主要是做一些周期性的任务,目前最主要的用途是定期备份数据Schedule one-time tasks with at. 一次性调度执行 atSchedule recurring jobs with cron. 循环调度执行 cronSchedule recurring system jobs.所有计划任务执行中的输出都会以邮件的方式发送给指定用户, 除非重定向

一次性调度执行 at [了解]

语法格式:at now +5min teatime tomorrow (teatime is 16:00) noon +4 days 5pm august 3 2018 例1:[root@CentOS7 ~]# at now +1minat> useradd uuuu at> job 1 at Sat Mar 21 22:34:00 2015[root@yang ~]# atq3Thu Mar 30 09:55:00 2017 a root[root@CentOS7 ~]# id uuuu例2:[root@yang ~]# vim at.jobs useradd u99useradd u00touch /`date +%F`.txt[root@yang ~]# at now +1min < at.jobs注: sudo执行需要考虑tty问题

循环调度执行 cron

[root@CentOS7 ~]# systemctl status crond.service[root@CentOS7 ~]# ps aux |grep crondroot 550 0.0 0.0 126300 1648 ? Ss 10:05 0:00 /usr/sbin/crond -ncrond进程每分钟会处理一次计划任务=====================用户级=====================存储位置:[root@CentOS7 ~]# ls /var/spool/cron/管理方式:crontab -lList the jobs for the current user.crontab -rRemove all jobs for the current users.crontab -eEdit jobs for the current user. 管理员可以使用 -u username, 去管理其他用户的计划任务禁止其他用户使用计划任务/etc/cron.deny:alicejack[alice@yang ~]$ crontab -eYou (alice) are not allowed to use this program (crontab)See crontab(1) for more information语法格式 Job format:Minutes Hours Day-of-Month Month Day-of-Week Command # 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# | | | | |# * * * * * command 0 2 * * * /mysql_back.sh0 2 14 * * /mysql_back.sh0 2 14 2 * /mysql_back.sh0 2 * * 5 /mysql_back.sh0 2 * 6 5 /mysql_back.sh0 2 2 * 5 /mysql_back.sh0 2 2 6 5 /mysql_back.sh */5 * * * * /mysql_back.sh0 2 1,4,6 * * /mysql_back.sh0 2 5-9 * * /mysql_back.sh* * * * * /mysql_back.sh0 * * * * /mysql_back.sh* * 2 * * /mysql_back.sh示例:00 02 * * * ls //每天2:00整00 02 1 * * ls //每月1号2:00整00 02 14 2 * ls //每年2月14号2:00整00 02 * * 7 ls //每周日2:00整00 02 * 6 5 ls //每年6月的周五2:00整00 02 14 * 7 ls //每月14号2:00整 或者 每周日2:00整,这两个时间都执行00 02 14 2 7 ls //每年2月14号2:00整 或者 每周日2:00整,这两个时间都执行00 02 * * * ls //每天2:00整* 02 * * * ls //每天2:00中的每一分钟* * * * * ls //每分钟执行ls* * 14 2 * ls //2月14号的每分钟 1440分钟*/5 * * * * ls //每隔5分钟00 02 1,5,8 * * ls //每月1,5,8号的2:00整00 02 1-8 * * ls //每月1到8号的2:00整=====================系统级=====================临时文件的清理 /tmp /var/tmp系统信息的采集 sar日志的轮转(切割)logrotate通常不是由用户定义定义位置一:[root@CentOS7 ~]# vim /etc/crontab //该文件中默认没有定义任何计划任务* * * * * user-name command to be executed定义位置二:/etc/cron.d/*[root@CentOS7 ~]# ls /etc/cron.d0hourly raid-check sysstat[root@CentOS7 ~]# cat /etc/cron.d/0hourly //该文件中定义的计划任务每小时会执行01 * * * * root run-parts /etc/cron.hourly //每小时01分以root用户执行/etc/cron.hourly目录下所有脚本

crond: 仅仅会执行每小时定义的脚本 /etc/cron.hourly

每小时具体执行哪些脚本:[root@CentOS7 ~]# ls /etc/cron.hourly/0anacron 0yum-hourly.cron[root@CentOS7 ~]# cat /etc/cron.hourly/0anacron /usr/sbin/anacron -s[root@CentOS7 ~]# vim /etc/anacrontab //该文件是anacron执行调用的文件#period in days delay in minutes job-identifier command1 5 cron.daily nice run-parts /etc/cron.daily7 25 cron.weekly nice run-parts /etc/cron.weekly@monthly 45 cron.monthly nice run-parts /etc/cron.monthly[root@yang ~]# ls /etc/cron.daily/0yum-daily.cron logrotate man-db.cron mlocate[root@yang ~]# ls /etc/cron.weekly/[root@yang ~]# ls /etc/cron.monthly/[root@CentOS7 ~]# ls /var/spool/anacron/cron.daily cron.monthly cron.weekly[root@CentOS7 ~]# cat /var/spool/anacron/cron.monthly 20170321=====================cron log=====================[root@CentOS7 ~]# tail /var/log/cronMar 29 20:01:01 CentOS7 run-parts(/etc/cron.hourly)[22456]: finished 0anacronMar 29 20:01:01 CentOS7 run-parts(/etc/cron.hourly)[22447]: starting 0yum-hourly.cronMar 29 20:01:01 CentOS7 run-parts(/etc/cron.hourly)[22462]: finished 0yum-hourly.cronMar 29 20:10:01 CentOS7 CROND[22563]: (root) CMD (/usr/lib64/sa/sa1 1 1)Mar 29 20:20:01 CentOS7 CROND[22688]: (root) CMD (/usr/lib64/sa/sa1 1 1)Mar 30 09:05:31 yang crond[1399]: (CRON) INFO (Syslog will be used instead of sendmail.)Mar 30 09:05:31 yang crond[1399]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 15% if used.)Mar 30 09:05:31 yang crond[1399]: (CRON) INFO (running with inotify support)Mar 30 09:10:01 yang CROND[1924]: (root) CMD (/usr/lib64/sa/sa1 1 1)Mar 30 09:20:01 yang CROND[2109]: (root) CMD (/usr/lib64/sa/sa1 1 1)计划任务cron就为您介绍到这里,感谢您关注懒咪学编程c.lanmit.com.

本文地址:https://c.lanmit.com/czxt/Linux/29886.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值