将web服务器上的脚本移植到db服务器上
http://xingyunbaijunwei.blog.163.com/blog/static/76538067201341294014683/
http://www.jb51.net/article/40944.htm
1 时程表的格式
crontab时程表的格式如下:
f1 f2 f3 f4 f5 program
f1 -分钟
f2 -小时
f3-一个月份中第几日
f4 -月份
f5 -一个星期中的第几天。
program 表示要执行的程式。
f1 为 * 时表示每分钟都要执行 program,
f2 为 * 时表示每小时都要执行程式,其余类推
f1 为 a-b 时表示从第 a 分钟到第 b 分钟这段时间内要执行,
f2 为 a-b 时表示从第 a 到第 b 小时都要执行,其余类推
f1 为 */n 时表示每 n 分钟个时间间隔执行一次,
f2 为 */n 表示每 n 小时个时间间隔执行一次,其余类推
f1 为 a, b, c,… 时表示第 a, b, c,… 分钟要执行,
f2 为 a, b, c,… 时表示第 a, b, c…个小时要执行,其余类推
例如
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
上面例子
第一个为每个小时的第17分钟执行
第二个任务为每天的6:25执行
第三个为每周周日的6:47执行
第四个任务为每月1日的6:52执行
所有用户定义的crontab 文件都被保存在 /var/spool/cron目录中。其文件名与用户名一致。
/var/spool/cron/ 该目录下存放所有用户的cron服务
/var/log/cron 记录cron运行的日志信息
2 cron服务
ubuntu下启动、停止与重启cron
sudo /etc/init.d/cron start
sudo /etc/init.d/cron stop
sudo /etc/init.d/cron restart
查看cron是否在运行:
pgrep cron
3 crontab命令
crontab 命令用于安装、删除或者列出用于驱动cron后台进程的表格。也就是说,用户把需要执行的命令序列放到crontab文件中以获得执行,每个用户都可以有自己的crontab文件。以下是这个命令的一些参数与说明:
1)crontab -u // 设定某个用户的cron服务
2)crontab -l // 列出某个用户cron服务的详细内容
3)crontab -r // 删除没个用户的cron服务
4)crontab -e // 编辑某个用户的cron服务
5)crontabl -ri //删除用户的Crontab文件前给提示
6) crontab -l -u jp //列出用户jp的所有调度任务
启动cron后,发现并没有产生日志,应该是cron日志服务没有打开
修改rsyslog
sudo vim /etc/rsyslog.d/50-default.conf
将
cron.* /var/log/cron.log
前面的注释去掉并重启rsyslog
sudo service rsyslog restart