1

I have a PHP script that runs perfectly fine on the command line if I simply run it like this php /path/to/script/script.php. if I now schedule this very command in cron using crontab -e and the add the line:

*/1 * * * * php /path/to/script/script.php 2>&1 >> /var/log/logfile.log

it does get executed every minute as expected and all the output gets put into the log file just like running it on the command line. But the some parts of the script just don't seemt o work. those particular parts are lines that are like:

system('mkdir /mnt/temp', $retVal);

or

exec('mkdir /mnt/temp');

I have tried every possible thing like running it as root, permissions on all scripts and folders that would be affected, using /bin/mkdir instead of mkdir. The return value from the system() is 0 for running it on CLI and 1 for the crontab way.

Any suggestions?

5
  • if its a temporary folder, why not create it inside /tmp? Commented Jan 24, 2013 at 7:50
  • a) sure the same php interpreter is called? The PATH variable might be different. And b) this might be a permission problem: sure the script is executed under the same user account? Using the same permissions and umasks? Commented Jan 24, 2013 at 7:53
  • 1
    Permissions most probably! you run the cron as same user as commandline? Commented Jan 24, 2013 at 7:54
  • using crontab -e -u root shows the job that i added so I would expect it to run as root Commented Jan 24, 2013 at 8:10
  • As @HankyPankyㇱ said, almost certainly a permissions issue. Commented Jan 24, 2013 at 8:29

1 Answer 1

2

I couldn't solve the CLI vs crontab issue, but the solution that worked for me was to use a bash script inside of cron. And that bash script in turn calls the PHP script. this works like a charm under any of the users that I need to run the script. So I can't say that it is or isn't a permissions issue.

Thanks for all your comments guys

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.