Search code examples
curlcroncron-task

Crontab cron job will not run with url with parameter


38  17  5   11  *    /usr/bin/sudo -u www /usr/bin/curl -sS "http://123.com/index.php?email=1&test=1"

I tried to run this php file that sends an email with a php class once receive these two parameters. But seems cron is not recognizing this command. I wonder where is the mistake here? or ways that I can run this in commandline and troubleshoot it will also be really helpful!

File runs perfectly in browser with exactly same url string.

I also tried another variation:

38  17  5   11  *       root    /usr/bin/sudo -u _www /usr/bin/curl -sS "http://123.com/index.php?email=1&test=1"

I have tried to do these crul command in commandline for testing :

curl "http://123.com/index.php?email=1&test=1"

and

curl "http://123.com/index.php?email=1\&test=1"

UPDATE

Now I tried this

echo "TEST" >> $CRONLOG
/usr/bin/sudo -u _www /usr/bin/curl -sS "http://123.com/index.php?email=1&test=1" >> $CRONLOG

UPDATE

the solution provided by fedorqui of escaping & worked well in my test file, so something else is wrong with my orignal file. Investigating

FINAL UPDATE

It came out that our authentication file that is included using php in the php file prevent the php file from going further! So its not (just) a syntax but a mix of forgetting escape & + auth file included.


Solution

  • As seen in the comments, the & character has a special meaning, so to make it be treated as literal you need to escape it.

    from

    38 17 5 11 * root ... curl -sS "http:// ... email=1&test=1"
    

    to

    38 17 5 11 * root ... curl -sS "http:// ... email=1\&test=1"
                                                       ^