Cron – script works manually but not in cron job

cron

I create my system graphs in rrd using perl script. When I run the script manually it'll update the graphs. On the other hand cron shows in logs that the job has been executed but it does not update graphs.. Any help please?

I've set apache2 directory permission root:apache with 770

Distro: CentOs 5.5.

Cron Config:

0,5,10,15,20,25,30,35,40,45,50,55 * * * *       /home/user/graphs/script-rrd.pl  > /dev/null 2>&1

I've already check /var/log/cron it shows that the above script has been executed but it does not update graphs in /var/html/www/graphs.png

Resolution of this issue:

cp -rf /opt/rrdtool-1.4.4/lib/perl/5.8.8/i386-linux-thread-multi/* /usr/lib/perl/site_perl

after copying rrd stuff in /usr/lib/perl5/site_perl issue has been resolved.

I've already created PERL5LIB. After creating PERL5LIB i was able to run scripts manually but it was not being run by cron so that is why i've to copied files as the above.

SELINUX is as following:
SELINUX=disabled
SELINUXTYPE=targeted
SETLOCALDEFS=0

Best Answer

There's an obvious mistake in your cron line: you redirect error output to /dev/null. Don't do this, and look at your mail to see what went wrong.

A common problem with cron jobs is that they get a very limited environment: your .profile is not read. You may need to define some environment variables for your script to run.

ADDED: You did:

cp -rf /opt/rrdtool-1.4.4/lib/perl/5.8.8/i386-linux-thread-multi/* /usr/lib/perl/site_perl

Bad idea! You should not put your own files in /usr (outside /usr/local). That area is reserved to the package manager. Sure, it's easy now, but you will run into trouble tomorrow (for example when you upgrade rrdtool), and it'll be hard to debug then.

Instead, do what people have been recommending and define the necessary environment variables in your script (or source ~/.profile); you need PERL5LIB (and perhaps others).

Related Topic