stakor
asked on
Cron environment issues
In Ubuntu, I am having a lot of trouble running a script that uses a .pm module from crontab. When I try to do so, I get an error that reads:
Can't locate <perl_module>.pm in @INC (@INC contains:<list_of_director ies_that_d o_indeed_h ave_the_pm _file>)
I was wondering if it would be possible to get the crontab to run the script as a specific user, in their environment. The script works perfectly from he command line...
Can't locate <perl_module>.pm in @INC (@INC contains:<list_of_director
I was wondering if it would be possible to get the crontab to run the script as a specific user, in their environment. The script works perfectly from he command line...
What user are you using to run the command? From that user
crontab -e
then as woolmilkporc suggested
* * * * * su - username -c /path/to/script
crontab -e
then as woolmilkporc suggested
* * * * * su - username -c /path/to/script
Only root can do "su - username" without password.
You could call your .profile first, like this:
00 10 * * * /home/user/.profile ; /path/to/script
00 10 * * * /home/user/.profile ; /path/to/script
ASKER
I tried the root path. I put in:
*/15 * * * * su -l <username> -c <command>
And, in a sureal turn of events, it is having the same error that I had in <username>'s crontab.
I am now trying the /home/<username>/.profile; <command>
idea. I'll post in about 20-25 min with how that works out. Something is up, but I don't know what...
*/15 * * * * su -l <username> -c <command>
And, in a sureal turn of events, it is having the same error that I had in <username>'s crontab.
I am now trying the /home/<username>/.profile;
idea. I'll post in about 20-25 min with how that works out. Something is up, but I don't know what...
ASKER
Sadly, same error.
Why "su -l" ? It's just "su - ..." I.e. a single dash surrounded by spaces after "su".
Nothing sureal here ...
Nothing sureal here ...
ASKER
I think I fat fingered it in the beginning. I used -<username>. I tried to get around this after man'ing su, and saw -l (at least I think I saw) that -l was another valid designator. I just tried it with - <username> and that had the same problem as "-l". It still can't find the .pm file.
ASKER
Ok, I have something that works. If I add:
setenv PERL_MB_OPT "--install_base /home/<USER>/perl5"
setenv PERL_MM_OPT "INSTALL_BASE=/home/<USER> /perl5"
setenv PERL_LOCAL_LIB_ROOT "/home/<USER>/perl5"
setenv PERL5LIB /home/<USER>/perl5/lib/per l5/i686-li nux-gnu-th read-multi -64int:/ho me/<USER>/ perl5/lib/ perl5
setenv PATH "$PATH":/home/<USER>/etc/t urfserf/et c:/home/<U SER>/perl5 /bin:/usr/ lib/lightd m/lightdm: /usr/local /sbin:/usr /local/bin :/usr/sbin :/sbin:/us r/games
to a csh file that calls the perl script, it works...
setenv PERL_MB_OPT "--install_base /home/<USER>/perl5"
setenv PERL_MM_OPT "INSTALL_BASE=/home/<USER>
setenv PERL_LOCAL_LIB_ROOT "/home/<USER>/perl5"
setenv PERL5LIB /home/<USER>/perl5/lib/per
setenv PATH "$PATH":/home/<USER>/etc/t
to a csh file that calls the perl script, it works...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I believe you may as well put environment variables at the top of your crontab of the user in question.
* * * * * su - username -c /path/to/script ...