0

First, I:

 sudo crontab -e -u adrian

Then I add:

 * * * * * cd /home/adrian/app/; perl -I /home/adrian/app/lib/ script/db/log_to_db.pl

This should make the script run every minute. This script modifies the database with new data. So I check my database every minute. No data. The "last update" time column doesn't change either. I check the log. Every minute this log appears:

 Jul  9 13:32:01 dev1 CROND[28658]: (adrian) CMD (cd /home/adrian/app/; perl -I   /home/adrian/app/lib/ script/db/log_to_db.pl)

Which looks like a succesful log. But the database doesn't change so the script is not running. Furthermore, if I execute the line on my command line manually:

  cd /home/adrian/app/; perl -I /home/adrian/app/lib/ script/db/log_to_db.pl

The database changes and the script runs without problem! What am I doing wrong here?

4

1 回答 1

2

由于该命令从命令行运行良好,因此问题很可能是缺少一些环境变量。与其直接从 cron 作业运行 perl,不如运行一个设置环境然后运行 ​​perl 的包装脚本。这样的事情应该可以工作(假设您使用 bash 登录——根据需要进行调整):

#!/bin/bash

source /home/adrian/.bash_profile
cd /home/adrian/app/
perl -I /home/adrian/app/lib/ script/db/log_to_db.pl
于 2013-07-09T04:50:39.090 回答