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

I am trying to pass the $EUID to a cshell script thats called from my perl script. ITs seems like its dropping the $EUID as it starts executing the called cshell script.

my $EUID = getpwnam(jjack); system("sleep 60"); #<< Executes it right as jjack system("/bin/csh -x ./submitjobs.csh");# This does not work. cshell script ./submitjobs.csh ------------------------------ #!/bin/csh source /net/watusi/usr1/lsf8.0/conf/cshrc.lsf echo $uid bsub -q lxpt64_2cpu -o /dev/null -e /dev/null sleep 10
This cshell script fails to be executed as "jjack"

Any one knows what I could do ? I need to execute several thousand LSF jobs as the EUID that I am parsing from a log file.

Replies are listed 'Best First'.
Re: Passing $EUID to cshell script through system command in Perl
by cdarke (Prior) on Jul 19, 2011 at 10:13 UTC
    In Perl, declaring a variable does not create an environment variable. Think of it being a bit like 'set' in C-shell. Instead, environment variables are exposed as a hash called %ENV.

    To pass an environment variable you need something like this:
    $ENV{EUID} = getpwnam(jjack);
    However it appears you actually want to run a program under a different user name, in which case you probably need to call something like su(1).

    Update: After more consideration, I think you are mis-understanding the EUID variable. This variable is set by bash, and it is readonly (in bash only). It is not normally exported, so will not be in the environment. EUID is not used by the C-shell so far as I can tell, and it neither reads nor writes to it.

      Thank you, after reading your $EID not available comment it made me think in terms of bash and im now executing the script as sudo and it seems to work.

      system("sudo -u $var1 /net/watusi/usr1/scripts/submitjobs.sh");

      here $var1 is jjack, file /net/watusi/usr1/scripts/submitjobs.sh below

      #!/bin/sh -p . /net/watusi/usr1/lsf8.0/conf/profile.lsf bsub -q lxpt64_2cpu -o /dev/null -e /dev/null sleep 10

      All these jobs are now being submitted into LSF with the Effective user id I wanted