rhg256 has asked for the wisdom of the Perl Monks concerning the following question:

I am automating regression testing using Perl sudo with the -H option to go from one account in one group to another account in another group. The problem is that the .profile is not being executed in the account being sudo'ed to and so the CLASSPATH is not defined. So, when I try to execute a java main class it fails with CLASSNOTFOUND exception because the CLASSPATH is undefined. A work around is to include SETENV in the sudoers and -E as a sudo option but this solution I do not like because now I have to maintain this really long classpath in both accounts. Why is the .profile login script not being executed? Is there any way to force execution? Thanks Perl Monks!

Replies are listed 'Best First'.
Re: [OT] sudo does not execute .profile
by ikegami (Patriarch) on Nov 11, 2010 at 23:24 UTC
    -i The -i (simulate initial login) option ...
      Thank you for your reply. I really appeciate the help ! This is a very odd problem. Here's the entire story... We connect remotely from an automated test script written in VBscript to a common test account on an AIX server. The VBscript simulates an interactive user login so the AIX server thinks someone is logging in and executing our first Perl script manually. This first Perl script calls Perl sudo with the -i option to execeute a second Perl script under a different uid and gid. Well now the .profile successfully executes (yeah!... I put an echo debug statement in there to be sure), but, (and this is the really strange part) when the second Perl script executes the environment variables defined in the .profile are no longer defined !!! I know this because at the top of the second Perl script I print out the important environment variables (print $ENV{'CLASSPATH'};) and they are all empty. Why??

        I think this is a Unix / AIX problem, not a Perl problem. Perhaps (a) missing export command(s) in .profile? Run env (or see below) instead of the second script and look at the output. Post the .profile file, if it does not contain sensitive data. Also post the relevant parts of the perl scripts.

        Simple env replacement:

        #!/usr/bin/perl -w use strict; use Data::Dumper; print Data::Dumper->new([\%ENV],['*ENV'])->Useqq(1)->Sortkeys(1)->Dump +();

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)