perl从cron运行时不执行壳命令
我有一个perl脚本,该脚本从命令行调用PHP脚本,并通过电子邮件发送输出。从命令行执行时,该脚本正常工作,但是通过Cron执行时会失败。我尝试从我自己的crontab以及root cron中执行脚本,结果相同。
这是脚本:
#!/usr/bin/perl
my $file = "/app/testing/testfile.php";
my $output = `php $file`;
#Sending e-mail here
这是它正在调用的php脚本:
fopen('/app/testing/log.txt', 'w');
fwrite('hi');
echo 'hi';
从命令行运行时,我会收到带有“ hi”一词的电子邮件,并且文件具有hi hi。从Cron运行,我收到一个空白的电子邮件,并且该文件未修改。
I have a Perl script which calls a PHP script from the command line and sends the output via e-mail. This script works fine when executed from the command line, but fails when executed via cron. I have tried executing the script from my own crontab, as well as the root cron, same result.
This is the script:
#!/usr/bin/perl
my $file = "/app/testing/testfile.php";
my $output = `php $file`;
#Sending e-mail here
And this is the PHP script that it is calling:
fopen('/app/testing/log.txt', 'w');
fwrite('hi');
echo 'hi';
When run from the command line, I get an e-mail with the word "hi" and the file has the word hi. Run from cron, I get a blank e-mail and the file is not modified.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
提供到
php
的完整路径:这是因为
cron
使用一个相当简化的环境,具有简约$ path
。另外,在
cron
中源来源。
Provide full path to
php
:This is because
cron
uses a rather simplified environment, with a minimalistic$PATH
.Alternatively, source your
.*rc
file incron
, but that may be an overkill: