Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
02-04-2009, 04:01 PM
|
#1
|
|
Member
Registered: Sep 2008
Location: Dominican Republic
Distribution: Debian Squeeze
Posts: 175
Rep:
|
Running a Cron Job
Hello.
I am trying to run a php script from crontab:
# m h dom mon dow command
25 0 5 * * root php -f /var/www/optimum/check_macs.php
I want it to run every 5th day of the month at 12:25am. I ran a test changing the system's time and setting it to about 5 minutes prior but, when it comes time, the script doesnt run.
I edited the crontab by issuing crontab -e as root and it generated a crontab for root.
I almost forgot to mention that, when I run the script from the command line: php -f /var/www/optimum/check_macs.php it works.
Does anyone have an idea of why the script is not running?
Thanks in advanced.
Last edited by landysaccount; 02-04-2009 at 04:07 PM.
|
|
|
|
02-04-2009, 04:06 PM
|
#2
|
|
Guru
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Squeeze, Fedora 14
Posts: 7,268
Rep:
|
One fairly common problem with cron jobs is that cron has a fairly skimpy PATH. The php compiler may not be on your cron's PATH. Try giving the full path to the php command in your cron statement.
----------------------
Steve Stites
|
|
|
|
02-04-2009, 04:30 PM
|
#3
|
|
Member
Registered: Sep 2008
Location: Dominican Republic
Distribution: Debian Squeeze
Posts: 175
Original Poster
Rep:
|
That didn't work either.
I tried /usr/bin/php in the crontab and still didn't work.
|
|
|
|
02-04-2009, 04:44 PM
|
#4
|
|
Member
Registered: Dec 2005
Distribution: Slackware -current, 14.0
Posts: 952
Rep: 
|
Another method may be to create a script with your command in it, then run the script from cron.
cheers,
|
|
|
|
02-04-2009, 05:13 PM
|
#5
|
|
Member
Registered: Sep 2008
Location: Dominican Republic
Distribution: Debian Squeeze
Posts: 175
Original Poster
Rep:
|
Tried that and still not working... The script is not running but, I noticed something in the /var/log/auth.log file:
Feb 5 00:09:01 debian CRON[2256]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 5 00:09:01 debian CRON[2256]: pam_unix(cron:session): session closed for user root
Feb 5 00:20:01 debian CRON[2303]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 5 00:20:01 debian CRON[2303]: pam_unix(cron:session): session closed for user root
Feb 5 00:25:01 debian CRON[2357]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 5 00:25:02 debian CRON[2357]: pam_unix(cron:session): session closed for user root
Feb 5 00:39:01 debian CRON[2376]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 5 00:39:01 debian CRON[2376]: pam_unix(cron:session): session closed for user root
Feb 5 00:40:01 debian CRON[2386]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 5 00:40:01 debian CRON[2386]: pam_unix(cron:session): session closed for user root
Feb 5 00:59:01 debian CRON[2404]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 5 00:59:01 debian CRON[2404]: pam_unix(cron:session): session closed for user root
Feb 5 01:05:01 debian CRON[2417]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 5 01:05:01 debian CRON[2417]: pam_unix(cron:session): session closed for user root
Feb 5 01:09:01 debian CRON[2426]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 5 01:09:01 debian CRON[2426]: pam_unix(cron:session): session closed for user root
Feb 5 01:17:01 debian CRON[2436]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 5 01:17:01 debian CRON[2436]: pam_unix(cron:session): session closed for user root
Feb 5 01:39:01 debian CRON[2462]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 5 01:39:01 debian CRON[2462]: pam_unix(cron:session): session closed for user root
Feb 5 01:40:01 debian CRON[2476]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 5 01:40:01 debian CRON[2476]: pam_unix(cron:session): session closed for user root
That looks like is trying to do something with cron but some how my script doesn't run.
What else can I do? I'm lost.
|
|
|
|
02-04-2009, 05:21 PM
|
#6
|
|
Senior Member
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Debian, FreeBSD, Ubuntu (desktop)
Posts: 3,859
Rep: 
|
Quote:
|
Originally Posted by landysaccount
25 0 5 * * root php -f /var/www/optimum/check_macs.php
...
I edited the crontab by issuing crontab -e as root and it generated a crontab for root.
|
In a user's crontab (even root's) you should not include the sixth field you have included. Remove "root" from that entry.
Also, it is a good idea to check the user's mail when you are having cron job issues.
|
|
|
|
02-04-2009, 05:29 PM
|
#7
|
|
Member
Registered: Sep 2008
Location: Dominican Republic
Distribution: Debian Squeeze
Posts: 175
Original Poster
Rep:
|
Ok.
I got it working.
Here's the solution:
instead of having 25 0 5 * * root php -f /var/www/optimum/check_macs.php with the root user in the line
I removed the root
25 0 5 * * php -f /var/www/optimum/check_macs.php
and it seem to work.
Thanks everyone for your help.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 02:08 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|