<?xml version="1.0" encoding="gb2312"?>
crondebug
Table of Contents
1 crontab添加任务的测试方法
在往crontab中添加定时任务时,往往不知道哪里出错了,因为看不到日志,在/var/log/auth.log(debian) 中能够看到简单的cron执行日志,但是出错信息却不能找到。 这里需要用到重定向2>&1命令,然后再把标准输出重定向到测试日志文件中,如下的一下crontab定时任务。
PATH="/usr/local/bin:/home/robin/.rvm/gems/ruby-1.9.3-p194/bin:/home/robin/.rvm/gems/ruby-1.9.3-p194@global/bin:/home/robin/.rvm/rubies/ruby-1.9.3-p194/bin:/home/robin/.rvm/bin:$PATH" 50 6 * * * /home/robin/.rvm/gems/ruby-1.9.3-p194@global/bin/rake -t -f /home/robin/rb/rake/Rakefile 2>> /home/robin/log/test.log 2>&1 31 18 * * * /home/robin/.rvm/gems/ruby-1.9.3-p194@global/bin/rake -t -f /home/robin/rb/rake/Rakefile mplay1 2>> /home/robin/log/mplayer.log 2>&1
对于用户自己安装的软件,在crontab的PATH中可能没有,于是可以在crontab任务前把使用到的命令路径指定。