linux 自动任务
(线上环境(centos 6.5)没有crontab 先安装执行yum install crontabs)
准备
# chkconfig crond on //开机自启动
# service crond start //启动
# /etc/init.d/crond restart //重载
备注: sql文件备份路径为 /backups/dumpups.sql
1 crontab命令选项
#crontab -u <-l, -r, -e>
2. cron文件语法与写法
可用crontab -e命令来编辑,编辑的是/var/spool/cron下对应用户的cron文件,也可以直接修改/etc/crontab文件。
3. 关于cron配置文件/etc/crontab
cron 的主配置文件是 /etc/crontab,它包括下面几行:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
0 0 * * * run-parts /etc/cron.hourly
4 linux脚本sh命令配置
#!/bin/sh
mysqldump -uyirong -pyirong2015 -hlocalhost -P3306 yirong --ignore-table=yirong.t_house > dumpups.sql
5. 特别提示
A、cron配置文件路径
#vi /etc/crontab
B、重启cron的方法
#/etc/rc.d/init.d/crond restart
Usage: /etc/rc.d/init.d/crond {start|stop|status|reload|restart|condrestart}
C、别忘了将脚本改成可执行
chmod +x filename
6 查看linux自动任务执行日志
tail -f var/log/cron
(线上环境(centos 6.5)没有crontab 先安装执行yum install crontabs)
准备
# chkconfig crond on //开机自启动
# service crond start //启动
# /etc/init.d/crond restart //重载
备注: sql文件备份路径为 /backups/dumpups.sql
1 crontab命令选项
#crontab -u <-l, -r, -e>
2. cron文件语法与写法
可用crontab -e命令来编辑,编辑的是/var/spool/cron下对应用户的cron文件,也可以直接修改/etc/crontab文件。
3. 关于cron配置文件/etc/crontab
cron 的主配置文件是 /etc/crontab,它包括下面几行:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
0 0 * * * run-parts /etc/cron.hourly
4 linux脚本sh命令配置
#!/bin/sh
mysqldump -uyirong -pyirong2015 -hlocalhost -P3306 yirong --ignore-table=yirong.t_house > dumpups.sql
5. 特别提示
A、cron配置文件路径
#vi /etc/crontab
B、重启cron的方法
#/etc/rc.d/init.d/crond restart
Usage: /etc/rc.d/init.d/crond {start|stop|status|reload|restart|condrestart}
C、别忘了将脚本改成可执行
chmod +x filename
6 查看linux自动任务执行日志
tail -f var/log/cron
backup.sh (sh脚本)
#!/bin/sh
mysqldump -uyirong -pyirong2015 -h10.66.108.12 -P3306 yirong --ignore-table=yirong.t_house >/backups/dumpups.sql