Setting up a cron job


#1

Hello,

Im trying to make cron run a PHP file every 5 minutes, this is the command im currently trying to use.

MAILTO="myemail@gmail.com"
*/5 * * * * wget http://mysite.com/mail.php

This is the error i am getting in my mailbox

–04:20:59-- http://mysite.com/mail.php

=> `mail.php’
Resolving mysite.com… 208.113.148.68
Connecting to mysite.com[208.113.148.68]:80… connected.
HTTP request sent, awaiting response… 404 Not Found
04:20:59 ERROR 404: Not Found.

As you can see cron automatically put ‘’ after the source path, thats why it cant be found. I am suspecting the extra blank line i put in the cron command is causing this, but when i leave the blank line out of it, the cron command does not run at all.

Thanks for any help in advance :slight_smile:


#2

Are you editing the file in the shell or uploading from your own machine?

:cool: [color=#6600CC]Atropos[/color] | openvein.org


#3

Thanks for the reply.

Since editting directly in the command prompt doesnt work for me (when i use crontab -e i get a whole lot of gibberish and i cant get out unless i close the window) i put the cron command in a txt file and uploaded it to my root directory. I then ran ‘crontab /home/username/cron.txt’ in the command promt. When running crontab -l it does show the command how it should be.


#4

Have you tried running that wget command from the command line? It looks like the cronjob is running, but there’s something wrong with the wget. Does mail.php need some parameters, such as mail.php?to=you&from=me, etc.?

Also, when I set up a cronjob, I use full paths just for assurance:
*/5 * * * * /usr/bin/wget http://mysite.com/mail.php

-Scott


#5

Due to the space where these jobs execute, you usually have to include the full path to the command you want to run. When I was setting up a cron job for my stats, which runs a perl script, “perl scriptname” didn’t work. I had to use “/usr/local/bin/perl scriptname”. While in the shell, do a “which wget”. For me it comes back as “/usr/bin/wget”.

So instead of:
"*/5 * * * * wget http://mysite.com/mail.php"

Try:
"*/5 * * * * /usr/bin/wget http://mysite.com/mail.php"

http://benconley.net
http://teamshocker.com


#6

DOH! Sorry for what is essentially a redundant post. I compose my replies in a text editor first, then paste them.

http://benconley.net
http://teamshocker.com


#7

Hey people, thanks for all the suggestions. The problem has been solved now by dreamhost support!