2
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.

fedorqui
  • 275,237
  • 103
  • 548
  • 598
ey dee ey em
  • 7,991
  • 14
  • 65
  • 121
  • What if you escape the `&`? `http://123.com/index.php?email=1\&test=1"` – fedorqui Nov 06 '14 at 14:40
  • Err in your updated answer you have `/&`, whereas I said `\&`. Which one did you try? – fedorqui Nov 06 '14 at 14:50
  • Ok! Mmmm to be on the safe side I would move this code to a script and call the script in the crontab. There must be some issue with escaping characters, etc. Also, did you check the logs from cron? Any traces? – fedorqui Nov 06 '14 at 14:53
  • 1
    @fedorqui I tried in a test file, the / escap worked! but not in my original file. I think there maybe something more complex going on in that file could cause this! Investigating! – ey dee ey em Nov 06 '14 at 15:24

1 Answers1

3

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"
                                                   ^
fedorqui
  • 275,237
  • 103
  • 548
  • 598