crontab无法执行perl脚本

时间:2020-02-14 19:49:39

标签: perl path cron raspberry-pi environment-variables

我在安排crontab任务时遇到问题;我已经在Google上搜索并阅读了大量页面,但是不知道给出的解决方案是否是示例特定的,并且它们似乎无法解决我的问题。

我正在尝试运行一个名为perl_speedtest.pl的基本perl脚本,该脚本位于我的树莓派的/home/pi/Documents/Projects目录中。当我通过上述目录中的命令perl perl_speedtest.pl手动运行脚本时,它运行完美。

我已通过在终端中使用“ crontab -e”命令将任务安排为使用以下crontab作业每20分钟运行一次:

*/20 * * * * perl /home/pi/Documents/Projects/perl_speedtest.pl

由于某种原因,此操作无法执行。愿意在需要时分享更多详细信息。

1 个答案:

答案 0 :(得分:0)

如上面的评论者所指出的,在cron中正确设置您的环境。另外,cron使用非常小的环境(包括PATHPERL5LIB等)。您的crontab应该看起来像这样,具体取决于您在交互式shell中使用它时的实际环境:

HOME=/home/pi
SHELL=/bin/bash
MAIL=/usr/bin/mail

06 */1 * * * source ~/.bashrc &> /dev/null ; perl /home/pi/Documents/Projects/perl_speedtest.pl

# or this (find the perl path by executing "which perl"):

06 */1 * * * /usr/bin/perl /home/pi/Documents/Projects/perl_speedtest.pl