cron job

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
dannyd
Forum Commoner
Posts: 56
Joined: Wed Jan 23, 2008 11:31 am

cron job

Post 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 ?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: cron job

Post 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
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
dannyd
Forum Commoner
Posts: 56
Joined: Wed Jan 23, 2008 11:31 am

Re: cron job

Post 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
marnieg
Forum Commoner
Posts: 65
Joined: Wed Mar 12, 2003 4:35 pm

Re: cron job

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: cron job

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
marnieg
Forum Commoner
Posts: 65
Joined: Wed Mar 12, 2003 4:35 pm

Re: cron job

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: cron job

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
marnieg
Forum Commoner
Posts: 65
Joined: Wed Mar 12, 2003 4:35 pm

Re: cron job

Post 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.
marnieg
Forum Commoner
Posts: 65
Joined: Wed Mar 12, 2003 4:35 pm

Re: cron job

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: cron job

Post 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]
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply