linux cron三言两语

作者: 弦乐之花 | 可以转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明

http://shiri512003.itpub.net/post/37713/499162

[@more@]

crontab对于dba而言应该是很熟悉的了,然而crontab到底做什么的呢?

crontab的man:

Crontab is the program used to install, deinstall or list the tables used to drive the cron(8) daemon in ISC Cron.Each user can have their own crontab, and though these are files in /var, they are not intended to be edited directly.

事实上crontab只是个传话的工具而已,或者只是个秘书,仵作,负责将用户想要定时执行的认为信息记录到相应的文件中。

真正负责执行认为的是cron - daemon to execute scheduled commands (ISC Cron V4.1)。

有时候为了测试脚本是否可以正常被cron调度执行,通常会手工在crontab里面编辑录入需要测试的脚本,而为了尽快得到结果,会把调度时间写成下一分钟,这时候也许会发生些意外,明明手工可以执行的脚步,明明可以确定和环境变量无关的脚步,却偏偏没有被调度,难到脚本有问题??

事实上看下cron的man

Cron searches /var/spool/cron for crontab files which are named after accounts in /etc/passwd; crontabs found are loaded into memory. Cron also searches for /etc/crontab and the files in the /etc/cron.d directory, which are in a different format (see crontab(5)). Cron then wakes up every minute, examining all stored crontabs, checking each command to see if it should be run in the current minute. When execut-ing commands, any output is mailed to the owner of the crontab (or to the user named in the MAILTO environment variable in the crontab,if such exists).Additionally, cron checks each minute to see if its spool directory's modtime (or the modtime on /etc/crontab) has changed, and if it has,cron will then examine the modtime on all crontabs and reload those which have changed. Thus cron need not be restarted whenever a crontab file is modified. Note that the Crontab(1) command updates the modtime of the spool directory whenever it changes a crontab.

1分钟一次的调度周期,如果刚好不幸错过了调度周期,那就会使脚本调度失败了。所以调试的时候至少要设置调度时间为sysdate+(1~2)min。

补充下,AIX下面cron的行为和linux有所不同,When you make changes to the crontab files using the crontab command, a message indicating the change is sent to the cron daemon. This eliminates the overhead of checking for new or changed files at regularly scheduled intervals.

再补充点crontab里设置环境变量

[oracle@db-test4 ~]$ crontab -l|grep my.log
24 * * * * w=hi;echo $w >>/home/oracle/my.log

[oracle@db-test4~]$ more my.log
hi

cron默认env

HOME=user’s-home-directory
LOGNAME=user’s-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7591490/viewspace-1032826/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/7591490/viewspace-1032826/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值