I have a script with a curl command in it for php to execute:


echo "test" > file
curl -d "credentials=foobar" -d "title=$server down" https://notifi.it/api

I can execute from the command line:

/usr/bin/php -r "echo shell_exec(\"/root/notify-down-script.sh test\");"

which works perfectly. When I add to the cron:

*       *       *       *       *       /usr/bin/php -d safe_mode=Off -r "echo shell_exec(\"/root/notify-down-script.sh test\");"

This does not call the curl (does call the echo). This is all ran as root. I have tried to catch the output (> /tmp/curl.log) of the curl in the script but nothing happens. I have tried to do the full path of the curl. I am completely lost. What am I doing wrong?

  • This is convoluted. Any reason not to just run your script directly, without PHP, as /root/notify-down-script.sh? Also, check cron logs for errors, or set MAILTO to an e-mail address to hopefully get an error report.
    – dhag
    Commented Feb 25, 2017 at 17:19
  • This is just an example of where it goes wrong. Imagine a massive php script and the exec is somewhere within. I have been trying to solve this all day!!
    – maxisme
    Commented Feb 25, 2017 at 18:25
  • I also know 100% the script is still exectued because I have another line like 'echo "hello" > file' which is executed
    – maxisme
    Commented Feb 25, 2017 at 18:28
  • OK. Can you try running your script with tracing enabled (set -x as the first line, or run with bash -x) and write the output of that somewhere? That should show how far the execution goes.
    – dhag
    Commented Feb 25, 2017 at 18:42
  • is PHP depending on an environment variable that you set but that cron does not? check for overrides with set|grep ^PHP. Also, you mention a curl.log but I don't see a reference to it in your code. Can you check the cron log for evidence of it being called?
    – Jeff Schaller
    Commented Feb 26, 2017 at 0:04

1 Answer 1


Try adding the full path to curl call inside your script, like this:

/usr/bin/curl -d "credentials=foobar" -d "title=$server down" https://notifi.it/api

  • Please see question. I have already tried that!
    – maxisme
    Commented Feb 25, 2017 at 20:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .