Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Script works when run with sudo, but not when run directly as root...?

by bmalnad (Initiate)
on May 07, 2014 at 20:42 UTC ( #1085377=note: print w/ replies, xml ) Need Help??


in reply to Re: Script works when run with sudo, but not when run directly as root...?
in thread Script works when run with sudo, but not when run directly as root...?

I can't find anything that makes any sense. dlamb@xxxxxxxxxx:~$ env && which perl

TERM=xterm SHELL=/bin/bash SSH_CLIENT=172.20.202.137 38907 22 SSH_TTY=/dev/pts/0 USER=dlamb MAIL=/var/mail/dlamb PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr +/games PWD=/home/dlamb LANG=en_US.UTF-8 SHLVL=1 HOME=/home/dlamb LANGUAGE=en_US: LOGNAME=dlamb SSH_CONNECTION=172.20.202.137 38907 172.21.202.5 22 LESSOPEN=| /usr/bin/lesspipe %s LESSCLOSE=/usr/bin/lesspipe %s %s _=/usr/bin/env /usr/bin/perl
root@xxxxxxxxxx:~# env && which perl
SHELL=/bin/bash TERM=xterm USER=root MAIL=/var/mail/root PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin PWD=/root LANG=en_US.UTF-8 SHLVL=1 HOME=/root LANGUAGE=en_US: LOGNAME=root LESSOPEN=| /usr/bin/lesspipe %s LESSCLOSE=/usr/bin/lesspipe %s %s _=/usr/bin/env /usr/bin/perl


Comment on Re^2: Script works when run with sudo, but not when run directly as root...?
Select or Download Code
Re^3: Script works when run with sudo, but not when run directly as root...?
by hippo (Curate) on May 07, 2014 at 21:00 UTC

    Unsurprisingly, the two environments you have listed there differ in the value of $HOME. Crypt::GPG uses this to find the keyrings, so if the keys aren't present on root's keyring, it won't stand a chance.

Re^3: Script works when run with sudo, but not when run directly as root...?
by Laurent_R (Parson) on May 07, 2014 at 22:13 UTC
    It is likely that hippo's message above gives the right explanation, but I can tell you that I met a similar problem with a (DBI-Oracle) script that worked perfectly under my user and did not under the crontab (i.e. root user) because of environment variables being defined differently. I wasted almost a full day figuring out what the problem was, quite a poor performance if you think that I originally wrote the whole script in 2 or 3 hours.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1085377]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2014-09-21 12:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls