script works manually but not in cron job

Solution 1:

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).

Solution 2:

My first guess would be paths of commands called within your script. When calling from cron, you don't get the environment settings your user does, so I would recommend every command being called in the script having a full path specified.

Solution 3:

crontab does not know vars that your shell would since it runs shellless. So if you run commands.. make sure its the full path.. if you read or write to files.. make sure you reference them via full path also.