LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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

Reply
 
Search this Thread
Old 02-04-2009, 04:01 PM   #1
landysaccount
Member
 
Registered: Sep 2008
Location: Dominican Republic
Distribution: Debian Squeeze
Posts: 177

Rep: Reputation: 17
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.
 
Old 02-04-2009, 04:06 PM   #2
jailbait
Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Wheezy, Debian Jessie
Posts: 7,503

Rep: Reputation: 174Reputation: 174
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
 
Old 02-04-2009, 04:30 PM   #3
landysaccount
Member
 
Registered: Sep 2008
Location: Dominican Republic
Distribution: Debian Squeeze
Posts: 177

Original Poster
Rep: Reputation: 17
That didn't work either.

I tried /usr/bin/php in the crontab and still didn't work.
 
Old 02-04-2009, 04:44 PM   #4
mrclisdue
Senior Member
 
Registered: Dec 2005
Distribution: Slackware -current, 14.1
Posts: 1,038

Rep: Reputation: 162Reputation: 162
Another method may be to create a script with your command in it, then run the script from cron.

cheers,
 
Old 02-04-2009, 05:13 PM   #5
landysaccount
Member
 
Registered: Sep 2008
Location: Dominican Republic
Distribution: Debian Squeeze
Posts: 177

Original Poster
Rep: Reputation: 17
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.
 
Old 02-04-2009, 05:21 PM   #6
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora, Lubuntu, FreeBSD
Posts: 3,930
Blog Entries: 5

Rep: Reputation: Disabled
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.
 
Old 02-04-2009, 05:29 PM   #7
landysaccount
Member
 
Registered: Sep 2008
Location: Dominican Republic
Distribution: Debian Squeeze
Posts: 177

Original Poster
Rep: Reputation: 17
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
script not running as a cron job sanjith11 Programming 5 11-23-2004 08:42 AM
cron job not running vincebs Linux - Software 34 10-30-2004 01:27 PM
Cron job not running in slackware9.1 marri Linux - Software 2 05-06-2004 06:54 AM
Cron job not running? james_cwy Linux - Newbie 6 12-14-2003 08:24 PM
Cron Job Not Running pzorn Linux - General 4 10-02-2003 01:38 PM


All times are GMT -5. The time now is 12:37 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration