PDA

View Full Version : Curl call from command line


StuartTP
2010-03-03, 12:26
Hello,

I have a php script that rebuilds some pages on a website and would like to run it in a cron job. The best way appears to be to use the CURL command.

The script can be run from a browser simply by calling it:
http://mydomain.com/index.php?page=build&auth=password

I have tried calling it from the command line using the following:

1) /usr/bin/curl http://mydomain.com/index.php?page=build&auth=password

2) /usr/bin/curl http://mydomain.com/index.php?page=build%26auth=password

3) /usr/bin/curl http://mydomain.com/index.php?page=build%26auth%3dpassword

4) /usr/bin/curl http://mydomain.com/index.php?page%3dbuild%26auth%3dpassword

5) /usr/bin/curl http://mydomain.com/index.php%3fpage%3dbuild%26auth%3dpassword

All of which fail!

Can anyone help?

Many thanks,

Stuart.

chucker
2010-03-03, 12:30
You need to put the URL in quotes, because bash will interpret the '&' differently otherwise. The following should work (with a default configuration, there's no need to prefix /usr/bin):

curl "http://mydomain.com/index.php?page=build&auth=password"

Brad
2010-03-03, 13:28
The following should work (with a default configuration, there's no need to prefix /usr/bin):
For server scripting, I've always heard (and followed) that it's good practice to specify the full path for security and compatibility reasons in case some other directory manages to get injected into $PATH.

chucker
2010-03-03, 14:05
For server scripting, I've always heard (and followed) that it's good practice to specify the full path for security and compatibility reasons in case some other directory manages to get injected into $PATH.

Fair enough. I must admit I had only skimmed the first few paragraphs; thought this was being done on an OS X client machine.

StuartTP
2010-03-03, 14:29
Hi Guys,

Many thanks for your comments. I needed both the quotes and the full path.

It is working fine now.

Stuart