dsfsd43523 2017-09-30 14:02
浏览 59
已采纳

通过cronjob执行PHP脚本 - 脚本中未读取/ var / www / html /目录中数据目录的路径

Here is a PHP script:

<?php 
$pathToDirectory = "/var/www/html/Tests/Workspace/data";
echo "pathToDirectory: " . $pathToDirectory . "
";
?>

In my Ubuntu 16.04 OS, I am trying to execute this script every minute as a part of a cronjob. I have added the cronjob like so to my root's crontab file:

* * * * * /var/www/html/Tests/Workspace/phpScript.php >/var/www/html/Tests/Workspace/logs/cronScriptOutput.out

And the cronjob runs successfully. The problem is that once the cronjob has run, following are the contents of the cronScriptOutput.out file.

pathToDataDirectory:

And that's it. That actual path string is NOT printed.

The question is why? How do I fix this.

This might not seem serious here, but the problem is that I need to read a file from that path and go further from there. So I need this fixed. I need that path to be read in my PHP script.

  • 写回答

1条回答 默认 最新

  • dqt20140129 2017-09-30 14:36
    关注

    May be you need add php before script name?

    * * * * * php /var/www/html/Tests/Workspace/phpScript.php >/var/www/html/Tests/Workspace/logs/cronScriptOutput.out 
    

    Of course, better use full path to php - /usr/bin/php - or what you have

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?