Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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 (Vicar) 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 (Prior) 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 examining the Monastery: (6)
As of 2015-07-03 21:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (56 votes), past polls