This is a cron question rather than a Pelr question.
When a cron job runs, by default it doesn't pick up your
environment variables. If you want the script to run in
your usual environment (and it sounds like that might well be your problem) then you'll need to explicitly run
your .profile. I generally do it like this:
. /home/dave/.profile && script.pl
--
<http://www.dave.org.uk>
Perl Training in the UK <http://www.iterative-software.com> | [reply] [d/l] |
crontab invokes a shell from your home directory with an arg0 of sh. If you need to set up your environment then run the .profile (or whatever your particular shell uses) as part of the cron statement.
I run the following from cron to successfully talk to an Informix database via DBI -
#Informix server processes
0 7 * * 1-5 . /.profile;. /usr/local/lib/dir_locations;. $INFORMIXDIR/
+lib/environ.ksh;$SERVERDIR/sbin/main_server.pl > /dev/null 2>&1
The .profile sets my environment.
The file dir_locations sets common directories for all users such as INFORMIXDIR, extensions to $PATH.
The file environ.ksh sets the required informix settings
main_server.pl is the perl script that starts the whole ball rolling.
Hope that is of some help
Graham | [reply] [d/l] |
This is a quite normal problem when running anything from cron:
You don't get your normal environment setup for you.
You will have to either add the neccessary parts of your environment in your script by hand, or ensure that /etc/profile and ~/.profile (or whatever the local names are in your preferred OS) are sourced before you execute anything in your cron jobs.
YMMV. | [reply] |
On (at least some variants of) Unix you can set up environment variables at the top of your crontab file:
% crontab -l
PERL5LIB=/home/echo/modules
1 * * * * /home/echo/script.pl
| [reply] |
As noted, (at least) Vixie's cron allows you to set environment variables. Some crons allow you to use the command field to set variables, thus:
ENV1=val ENV2=val command
Also, note that when you run from the command line your script has an open STDIN and an open STDOUT. In cron you do not have an open STDIN. STDOUT is generally a mail program. It is possible that cron errors are going to root. If you are not the admin, ask someone who is to see where cron errors go and if your script got any.
HTH, --traveler | [reply] [d/l] |
| [reply] |
Thanx a lot that tip did work. I wrote a wrapper to setup all the environment variables and then ran the script and that worked.
Thanx a lot guys. | [reply] |
If you post your code you are more likely to get useful replies.
-- Snazzy tagline here
| [reply] |