how do i run a cron job ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

how do i run a cron job ?

Post by lazy_yogi »

I have a script chaseUp.php and it's on linux.

does anyone know the exact commands I would need to type into the command prompt to make this be run automatically everyday at 6pm ?

Cheers
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post by Kriek »

Code: Select all

crontab -e

0 6 * * * /usr/bin/php your/path/chaseUp.php >/dev/null
Depending on your application, you might prefer to use wget

Code: Select all

crontab -e

0 6 * * * wget - O - http://www.yoursite/chaseUp.php
Last edited by Kriek on Wed Apr 23, 2003 8:03 pm, edited 2 times in total.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

A simple Google search has many answers to questions you might have about cron.

BTW: http://cronjobs.com has a nice service if your host doesn't offer you cron or it is impossible for you to get it. :)
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Oromian: Care to give me $10? ;)
Image Image
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post by lazy_yogi »

Kriek wrote:

Code: Select all

crontab -e

0 6 * * * /usr/bin/php your/path/chaseUp.php >/dev/null

Hey Kriek, just wondering what the asterisks are for ....

And what "/usr/bin/php" is for

And the >/dev/null thing too ? .. does that send output to be deleted or something ?

Cheers,
Eli
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

phice wrote:Oromian: Care to give me $10? ;)
lol... sure if you don't mind the 1000% interest. :wink:
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Oromian wrote:
phice wrote:Oromian: Care to give me $10? ;)
lol... sure if you don't mind the 1000% interest. :wink:
I knew there would be some circumstance... >_<
Image Image
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

If your server doesn't support to run a php file directly try this perl script.
And put the perl script in a cronjob.

Code: Select all

#!/usr/bin/perl
require "http-lib.pl";
$p = &HTTPGet("/page.php","www.domain.com",80,"?foo=bar");
print $p;
:roll:
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post by Kriek »

lazy_yogi wrote: what the asterisks are for?
Each Cron Job record is composed of six fields: Minute (0-59), Hour (0-23), Day of Month (1-31), Month of Year (1-12), Day of Week (0-6), and the Command. An asterisk can be used as a wildcard to signify all values in a field. For example, by placing an asterisk in the 3rd field, the Cron Daemon will run a job every day. In the sixth field of each entry, long, complex commands can be added.
lazy_yogi wrote:what "/usr/bin/php" is for
Most PHP installations include CGI/CLI support, so you can execute a PHP script using the Order PHP which is commonly /usr/local/bin/php or /usr/bin/php in UNIX.
lazy_yogi wrote:>/dev/null thing too
Email is Crontab's way of notifying you that it has completed (or not) the job you requested it to run. After everything is running smoothly, you may want to disable this feature, or redirect the output to a log file instead of an email.
leebo
Forum Commoner
Posts: 44
Joined: Sun Oct 20, 2002 9:49 am

Post by leebo »

*/15 * * * * lynx -dump http://www.yourdomain.com/script.php

this will work - this will make the script work every 15 minutes.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Isn't it nice that you can get one task done in so many ways if you are using linux?
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

phice wrote:
Oromian wrote:
phice wrote:Oromian: Care to give me $10? ;)
lol... sure if you don't mind the 1000% interest. :wink:
I knew there would be some circumstance... >_<
as always. heh ^_^
Post Reply