Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need to set up a cron job in cpanel that calls a URL (on the same server) once a week. I was going to use wget but it turns out this is disabled on the shared server being used.

Is there an alternative to wget? I've heard that curl can be used but I don't know how to set that up in a cron command.

Also, what's the command to make the cronjob do nothing on completion?

Any ideas greatly appreciated!

share|improve this question
1  
What would the wget do if you could use it ? –  Iain Aug 9 '11 at 16:32
    
Why would they allow curl in case they have disabled wget? –  andol Aug 9 '11 at 16:36
    
@Iain - it's needed to process a PHP script –  davidhyland Aug 9 '11 at 16:38
    
@Andol - very good question. that's just how it is –  davidhyland Aug 9 '11 at 16:38

2 Answers 2

up vote 6 down vote accepted

instead of using wget, curl works like this:

curl --silent http://domain.com/cron.php

which will work in the same way as wget. if its a php file you are launching, is there any reason you cant run it via the command line php interpreter like so:

php -q /path/to/cron.php

same on a webserver request and often will work much faster and without certain timeout restrictions present when called via webserver/curl

share|improve this answer
    
Calling curl that way will print the result to stdout. If you want to behave equivalent to wget, and save the output to a file name based on the url, you also want to add the --remote-name flag. –  andol Aug 9 '11 at 16:34
    
does the --silent mean that there's no response or output? –  davidhyland Aug 9 '11 at 16:39
    
Also, calling the php script from the command line might not necessarily yield the same result. In addition to the possibility of different configuration there is also the not uncommon scenario of the script being run as a different user that way. It alls depends on the setup. –  andol Aug 9 '11 at 16:43
    
Well, I got it to work using "curl --silent domain.com/script.php >/dev/null 2>&1" but it also works fine with "curl -o --url domain.com/script.php >/dev/null 2>&1" what's the difference? –  davidhyland Aug 9 '11 at 17:14
    
The first command sends all output to /dev/null, the second will create a file called -url in the home directory of the user running the script, which contains the output of your php file, all other output goes to /dev/null. –  Iain Aug 10 '11 at 7:21

If curl is available you could try something like

1 1 * * 0  /usr/bin/curl --silent http://example.come/some.php &>/dev/null

That should cause curl to be completely silent so you don't get any email from it on completion.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.