Run on the command line it works no problem.
Run using crontab it doesn't work.
Where do I go to check errors from crontab?
I've read things about the cron ENVIRONMENT which I don't understand.
Could someone please explain to me what I need to know about crontab before I start using it?
You would have to write a script that loads the environment first then calls your perl script.
The best to avoid interactive shell issues to put in a separate file you call e.g. profile_perl where you have all needed environment variables set, then you execute it in your batch script for cron as:
Ok i'm getting that I need to set some environment variables but what variables are these?
What do I need to set them to and how do I set them (yes this thread is appropriately titled!)
You set any env variable you need except DISPLAY, TERM TTY and other keyboard stuff since there arent any for cron...
I would imagine PATH is very important and for the rest, look in your .profile or its equivalent what is set that could be used by your script
to set (since cron uses ~/bin/sh):
Supposing all I care about is the /usr/bin directory (assuming that this is the one PERL cares about), can I manually go to this PATH variable and set it = to /usr/bin or are these variables not sitting in a file somewhere like a config file?
/usr/bin is maybe the only thing set in cron with /bin, so if it isnt working then you have more to think about (using libraries? perl can have env settings like java does...)
Yes, write a simple one-off cron containing something like
env > /tmp/cronenv.txt
It can be most revealing to find out how basic the environment is when running from cron. It is extremely unlikely that the default $PATH will know about Perl (... unless you have changed it). The normal fix is to write a Shell script which sets up (and exports) the Environment Variables you need and then runs the Perl script.
If you cron is failing for a fundamental reason the error messages will be in unix mail for the owner of the cron.
To answer in any further detail, please post what Operating System and version you are running and what Shell you use for system scripts. You need to post this basic information in every thread.
Sorry guys I am slowly starting to understand what I need to do. I basically need to make cron do the env command and stick the result in a file so I can see what environment variables IT deals with when it runs.
Now you are starting to understand...
the command whoami and similar are using things that are initialized at logging time but cron ignores all about that since it is not associated to a terminal to start with...
Did you compare the output of env using cron, and typing in your interactive shell?
I looked into my home directory and found a local.profile and tried to run this before my script like vbe and vgersh suggested but I guess my syntax could be wrong