?
Solved

Problems with CRON

Posted on 2006-04-26
13
Medium Priority
?
6,165 Views
Last Modified: 2008-01-16
Hi,

I have inserted the following line in my crontab:

*/5 * * * * cactiuser /opt/lampp/bin/php /opt/lampp/htdocs/cacti/poller.php

The CROND is running fine and /var/log/cron shows clearly that the cron is being executed:

Apr 26 12:00:01 NagiosWCMPTSI crond[23048]: (cactiuser) CMD (cactiuser /opt/lampp/bin/php /opt/lampp/htdocs/cacti/poller.php )

However, nothing is being generated i.e. the cron is not being executed..

Why is this so ? whats wrong with my crontab ?

thnx
0
Comment
Question by:sgaucho
  • 4
  • 3
  • 2
  • +3
13 Comments
 
LVL 43

Expert Comment

by:ravenpl
ID: 16542991
Is the php file executeable (has execute bit set?)
Is the first line of php file like:
#!/usr/bin/php-cli
or
#!/usr/bin/php -q
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16543410
what should cactiuser be in you crontab line? Are you using a proprietary crond with its own format in crontab?
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 16543552
/etc/crontab allows to execute jobs as different user from root. I guess it's the username, and same suggests the log entry...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 43

Expert Comment

by:ravenpl
ID: 16543570
In fact I am wrong in my previous comment.
Yes, author, You have to remove the 'cactiuser' entry, as cron tries evaluate this as command to run
CMD (cactiuser /opt/lampp/bin/php /opt/lampp/htdocs/cacti/poller.php )
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16543765
hmm, that's what I guess, but have tooooo often seen people running propritary software and I got bashed for the standard answer :-/ hence my deliberated question ...
0
 
LVL 6

Expert Comment

by:bira
ID: 16545159
generate an error log by redirection output to find what
is going on:

cactiuser /opt/lampp/bin/php /opt/lampp/htdocs/cacti/poller.php 2> /tmp/catiuser_error.log
0
 

Author Comment

by:sgaucho
ID: 16545182
I have to execute the PHP file in question as user  "cactiuser" and not as root. Hence the "cactiuser" before the command.
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 16545252
> Apr 26 12:00:01 NagiosWCMPTSI crond[23048]: (cactiuser) CMD (cactiuser /opt/lampp/bin/php /opt/lampp/htdocs/cacti/poller.php )
It says it's executing the command as cactiuser ...

Have You creted the crontab entry as cactiuser or root? In the first case cron handles it automatically, otherwise add exactly same entry as You already did to the /etc/crontab
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16545657
I guess a standard cron where the last command has to follow the time fields in the crontab, in the given example "cactiuser" seems to be obsolete
0
 
LVL 48

Accepted Solution

by:
Tintin earned 320 total points
ID: 16548517
/etc/crontab is part of vixie-cron found on pretty much all Linux distributions.

There's so many ways to define a cronjob on a Linux box (in fact, it can be damm confusing trying to find all the cronjobs).

The format for /etc/crontab is:

cactiuser /opt/lampp/bin/php /opt/lampp/htdocs/cacti/poller.php 2> /tmp/catiuser_error.log

times user command

Try changing the cronjob to:

*/5 * * * * cactiuser /opt/lampp/bin/php /opt/lampp/htdocs/cacti/poller.php >/tmp/cactiuser 2>&1

Then look in /tmp/cactiuser after it has run.
0
 
LVL 27

Expert Comment

by:Nopius
ID: 16549947
sgaucho:
1) what is your OS: uname -a
2) did you read 'man crontab'?
3) where is your crontab is located? It can be either in /etc/crontab, /var/spool/cron or in some other places. Crontab format is different for that different locations.
4) how do you get use of your crontab? You just edit /etc/crontab  or edit some other /tmp/crontab and excute 'crontab' command? If you are running 'crontab' from which user?
0
 

Author Comment

by:sgaucho
ID: 16550997
Solved it...

as root, I edited /etc/crontab and inserted the line :
*/5 * * * * cactiuser /opt/lampp/bin/php /opt/lampp/htdocs/cacti/poller.php
but this didnt work

as cactiuser i did the same as above but even this didnt work..

I create a cron file in /etc/cron.d and inserted the line:
*/5 * * * * cactiuser /opt/lampp/bin/php /opt/lampp/htdocs/cacti/poller.php

and voila its executing fine.. can anyone please explain this ?

My OS is Linux CENTOS 4

TIA,
sg

0
 
LVL 48

Expert Comment

by:Tintin
ID: 16557928
That's very strange.

It should be working just fine from /etc/crontab.  My only thought is it could be environment.  The default /etc/crontab has:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/


set in it.  This may cause your script to fail.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question