计划任务
Posted Weblog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了计划任务相关的知识,希望对你有一定的参考价值。
日计划 #####
一、at 一次性计划任务
# yum install at -y # at 23:23 指定当天的时间去执行问题; # at -l 查看计划任务 -c 查看编号任务 -d 删除编号的任务
二、
周期性计划任务 ###########
cron
crontab 计划任务;
crontab 命令的功能就是在一定时间间隔调度一些命令的执行;在/etc/crontab文件;
1、安装crontab: [[email protected] ~]# yum install vixie-cron [[email protected] ~]# yum install crontabs
2、说明: vixie-cron软件包是cron的主程序; crontabs软件包是用来安装、卸装、或列举用来驱动 cron 守护进程的表格的程序。 //+++++++++++++++++++++++++++++++++++ cron 是linux的内置服务,但它不自动起来,可以用以下的方法启动、关闭这个服务: /sbin/service crond start //启动服务 /sbin/service crond stop //关闭服务 /sbin/service crond restart //重启服务 /sbin/service crond reload //重新载入配置
4、查看crontab服务状态:service crond status 5、手动启动crontab服务:service crond start 6、查看crontab服务是否已设置为开机启动,执行命令:ntsysv 7、加入开机自动启动: chkconfig --level 35 crond on
三、
参数:
1、crontab 文件的格式:M H D m d M: 分钟(0-59)。 H:小时(0-23)。 D:天(1-31)。 m: 月(1-12)。 d: 一星期内的天(0~6,0为星期天) date *号代表是默认的
2、crontab 基础操作 -e :编辑用户的crontab -l:列出用户的crontab的内容 -r:删除用户的crontab的内容
四、
示例:
30 23 * * * /usr/local/etc/rc.d/lighttpd restart 表示每晚的23:30重启apache 05 0 1,10,20 * * /usr/local/etc/rc.d/lighttpd restart 表示每月1、10、20号的0 : 05重启 apache 10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart 表示每周六、周日的1 : 10重启apache 0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart 表示在每天18 : 00至23 : 00之间每隔30分钟重启apache 0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart 表示每星期六的11 : 00 pm重启apache * */1 * * * /usr/local/etc/rc.d/lighttpd restart 每一小时重启apache * 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart 晚上11点到早上7点之间,每隔一小时重启apache 0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart 每月的4号与每周一到周三的11点重启apache 0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart 一月一号的4点重启apache */30 * * * * /usr/sbin/ntpdate 210.72.145.44 每半小时同步一下时间 0 6-12/3 * 12 * backup.sh 在 12 月内, 每天的早上 6 点到 12 点中,每隔3个小时执行一次 backup.sh
以上是关于计划任务的主要内容,如果未能解决你的问题,请参考以下文章