Page 1 of 1

cron job

Posted: Mon Feb 25, 2008 11:07 am
by dannyd
I created a php script and I want it to run everyday at 10:30am. How would I make that into a cron job ?

Re: cron job

Posted: Mon Feb 25, 2008 11:30 am
by s.dot
Create a crontab command for the entry.

Usually if you have a front-end control panel it makes it way easy.

Anyways you have to put in your time, which would be:

Code: Select all

30 10 * * *
Then you need the entry in the format of /path/to/php /path/to/script.php, such as:

Code: Select all

/usr/bin/php /home/me/public_html/myscript.php

Re: cron job

Posted: Mon Feb 25, 2008 11:34 am
by dannyd
Is it possible to run the cron job on the command line to test ?

So far I've added the line:

30 10 * * * /script

Instead of having this line referencing to php:

/usr/bin/php /home/me/public_html/myscript.php

will adding this line at the top be the same:

#!/usr/local/bin/php -q

Re: cron job

Posted: Mon Jun 28, 2010 1:20 pm
by marnieg
I'm having a similar problem, but here is my environment and issue.

I'm using Putty for my connection to SSH. After logging in I use the command

crontab -e which opens the editor

I put the following commands in

# email for course start alert everyday at 8 am
00 08 * * * /usr/local/bin/php /var/www/vhosts/wtionline.cc/crontasks/emailcoursealert.php

My php file is listed under my hosting directory as stated in the path.

First, my question is how do I SAVE this file and where is it placed on the hosting server?
If I want to edit it again how do I do this. I'm assuming these are all command line functions, but not familiar with linux or putty.

Re: cron job

Posted: Mon Jun 28, 2010 1:29 pm
by AbraCadaver
marnieg wrote: First, my question is how do I SAVE this file and where is it placed on the hosting server?
Depends on the editor. If vim or vi you do SHIFT : then x to save and exit. For Gnu Nano it is CTRL o and then CTRL x I think. Where it saves it is dependent on the Linux distribution. Mine is /var/spool/cron/crontabs
marnieg wrote:If I want to edit it again how do I do this. I'm assuming these are all command line functions, but not familiar with linux or putty.
Just do 'crontab -e' again.

Re: cron job

Posted: Mon Jun 28, 2010 2:49 pm
by marnieg
When I login it says "The program included with the Debian GNU/Linux system are free software. So I tried your Ctrl o and nothing happened. Also tried the SHIFT : but just got the characters :. The Ctrl just backed up the cursor one character to the left.

I will continue to google putty and see if I find other information.

Any other suggestions welcomed.

Re: cron job

Posted: Mon Jun 28, 2010 2:55 pm
by AbraCadaver
marnieg wrote:When I login it says "The program included with the Debian GNU/Linux system are free software. So I tried your Ctrl o and nothing happened. Also tried the SHIFT : but just got the characters :. The Ctrl just backed up the cursor one character to the left.

I will continue to google putty and see if I find other information.

Any other suggestions welcomed.
It doesn't have anything to do with putty, it has to do with what the default editor on your system is.

Re: cron job

Posted: Mon Jun 28, 2010 3:28 pm
by marnieg
Yes I found figured out it was using the vi editor from my hosting company. I was able to create a file with my command and now just waiting to see if it works. I'm assuming the job is ready to run based on the Linux Server and it looks for cron jobs automatically.

Re: cron job

Posted: Tue Jun 29, 2010 10:23 am
by marnieg
My job is not executing for some reason.

I contacted my hosting company to figure out the path for the file location and used pwd to get that information. Here is my final script

0 10 * * * /homepages/41/d283671596/crontasks/emailcoursealert.php


Is there a way for me to get a notice of whether the job had errors or executed at all. This should have ran at 10 AM Central time, which is the time of my server. The php script should be sending me an email message.

This is the only line in my script file.

Re: cron job

Posted: Tue Jun 29, 2010 1:27 pm
by AbraCadaver
Well, if you are using the !#/usr/bin/php method then you need to set emailcoursealert.php to be an executable.
[text]CHMOD +x emailcoursealert.php[/text]

For the mail issue, add this to the top of the crontab:
[text]MAILTO=you@example.com[/text]