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 have a web page at http://mydomain.com/process/2909

I want a cron job to automatically hit this page every night at 2 am. I was going to get cron to run a PHP script that opens the website with CURL like so:

        $bocURL = 'http://mydomain.com/process/2909';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $bocURL);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $bocFile = curl_exec($ch);
        curl_close($ch);

Is there a way for me to do this directly from a cron command without having to write PHP script?

share|improve this question
3  
0 2 * * * /usr/bin/wget --quiet --output-document=/dev/null http://mydomain.com/process/2909 # get page at 2am, do not save output, be quiet –  L.R. Mar 4 '10 at 20:20

3 Answers 3

up vote 10 down vote accepted

The command wget is a good solution for this problem if you are accessing a script on a remote server. However, if you are running the cronjob on the actual host that is "mydomain.com" you may just want to schedule crobjob to execute the code sitting at /process/2909.

For example, we have some PHP jobs that we execute with cron. Rather than using an HTTP request that could take minutes (and potentially cause timeout issues) we setup a cronjob that calls "php5 /srv/cronJobs/2909.php" - This invokes the PHP interpreter and is not subject to HTTP timeouts. Additionally, this PHP process is separate from Apache so the scheduled job will not die in case a sysadmin restarts httpd.

share|improve this answer

yes you can use wget or curl

as direct commands or from a shell script

share|improve this answer

Note that the selected answer only works if you're interested in getting some html directly from a URL. If you need to wade through some UI stuff before you get to the page you need, I'd recommend running Selenium on a headless X server. I'm doing that for a project now, it works like a charm.

Hope this helps.

Regards,

Sebastiaan

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.