LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-16-2009, 01:21 AM   #1
bangsters
Member
 
Registered: May 2009
Posts: 51

Rep: Reputation: 15
running php script via cron....


Hi.

I need to run a particlar file (file.php) every x hours or so. I have set it in cron using wget "wget -O /dev/null /home/user/file.php".

Is that the correct syntax? If I try to run that same synax directly in SSH I can an "Unsupported scheme" error. But if I run tha script in console using "php /home/user/file.php" it works and outputs the result in the console.

Which syntax should I use for the cronjob?

Thanks!
 
Old 09-16-2009, 01:50 AM   #2
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by bangsters View Post
Hi.

I need to run a particlar file (file.php) every x hours or so. I have set it in cron using wget "wget -O /dev/null /home/user/file.php".

Is that the correct syntax? If I try to run that same synax directly in SSH I can an "Unsupported scheme" error. But if I run tha script in console using "php /home/user/file.php" it works and outputs the result in the console.

Which syntax should I use for the cronjob?

Thanks!
wget retrieves a file from the provided path, it doesn't run it, so it's the wrong approach. Why not use the same method that worked from the command line? But remember that, depending on how you set up the cron schedule, the task may run with root privileges.

One way to solve this problem is to (1) use an up-to-date distribution and version, and (2) place the following in a file with any name located under /etc/cron.d:

30 * * * * (user name) /usr/bin/php /path/to/php/file.php

This entry will cause "file.php" to run every hour on the half-hour. Make sure the PHP script doesn't produce any output requiring a terminal. Or you can trap its output:

30 * * * * (user name) /usr/bin/php /path/to/php/file.php > /dev/null 2>&1
 
Old 09-16-2009, 09:25 AM   #3
bangsters
Member
 
Registered: May 2009
Posts: 51

Original Poster
Rep: Reputation: 15
thanks! i got it to work
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cron job running PHP script to update MySQL - access denied error Beauford2008 Linux - Newbie 9 09-24-2008 07:17 PM
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
cron NOT running php script ??!! hendrixx Linux - Software 2 11-15-2006 07:18 AM
cannot get tu run a php script in cron alain Linux - General 6 02-06-2006 02:54 AM
cron NOT running php script ??!! hendrixx Programming 1 01-19-2005 05:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration