LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Errors when running Perl script in a cron job (https://www.linuxquestions.org/questions/slackware-14/errors-when-running-perl-script-in-a-cron-job-456572/)

meshach 06-20-2006 10:12 AM

Errors when running Perl script in a cron job
 
I have a Perl script that uses several pm files like XMP/RSS.pm. I can run these scripts just fine and root can run them fine but when I put them in a cron job they fail to run. Examining the log file, the error is that the file XML/RSS.pm cannot be found.

My question is what user do cron jobs run as? Is there a way to add the @INC file string to that user so that the scripts can run properly? Or am I doing something else wrong?

Thanks,
Caleb

MensaWater 06-20-2006 02:53 PM

Cron runs as the user who owns the cron file. Presumably you're talking about the root cron so it runs as root.

However cron runs a minimal environment. It does NOT invoke .profile, .bashrc or other config files that you do when you login. When you run a command from the command line it inherits the environment from these config files that you had when you logged in. However the cron has nothing to inherit because of the minimal environment it runs.

Therefore the key is to insure that any varaible (PATH being the most common one) that is set when you are logged in needs to be added to your environment within the script itself. Alternatively you can speicify full paths to items. So where in a command line script you might just say "ls -l" in the cron script you need to have "/bin/ls -l" so it will know ls is in /bin.

meshach 06-20-2006 09:10 PM

Thanks jlightner, that was the fix I needed.


All times are GMT -5. The time now is 02:27 PM.