|
|
发表于 2015-1-13 22:55:30
|
显示全部楼层
配合 crontab
以下教程:
说明:Crontab是Linux系统中在固定时间执行某一个程序的工具,类似于Windows系统中的任务计划程序;
操作系统:Cent OS 6
一、安装crontab
yum install vixie-cron #安装
chkconfig crond on #设为开机启动,先要安装chkconfig[yum install chkconfig]
service crond start #启动
service crond stop#停止
service crond restart #重启
/etc/rc.d/init.d/crond restart#重启
/etc/rc.d/init.d/crond start#启动
/etc/rc.d/init.d/crond stop#停止
二、设置计划任务
/root/root.sh#要自动执行的脚本程序路径
chmod +x /root/root.sh#对脚本文件添加执行权限,否则不能执行
vi /etc/crontab#编辑配置文件,在最后一行添加内容
50 14 * * * root /root/root.sh#表示每天14:50分执行root.sh这个脚本
:wq!#保存退出
/etc/rc.d/init.d/crond restart#重启
说明:
crontab文件的格式说明:
minute:分,值为0--59
hour:时,值为1--23
day:天,值为1--31
month:月,值为1--12
weekday:星期,值为0--6 【0代表星期日,1代表星期一,一次类推】
username:要执行程序的用户,一半设置为root
command:要执行的程序路径【绝对路径】
附:crontab规则详细实例
1.每天6:00执行
0 6 * * * root/root/root.sh
2.每周六凌晨4:00执行
0 4 * * 6 root /root/root.sh
3.每周六凌晨4:05执行
5 4 * * 6 root /root/root.sh
4.每周六凌晨4:15执行
15 4 * * 6 root /root/root.sh
5.每周六凌晨4:25执行
25 4 * * 6 root /root/root.sh
6.每周一到周五的11:41开始,每10分钟执行一次
1-59/10 12-23 * * 1-5 root /root/root.sh
7.每天的10:31开始,没隔2小时执行一次
31 10-23/2 * * * root /root/root.sh
|
|