LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-22-2009, 11:14 AM   #1
powah
Member
 
Registered: Mar 2005
Distribution: FC, Gentoo
Posts: 276

Rep: Reputation: 30
sudo perl script with environment variables


How to use sudo to run a perl script with the environment variable JAVA_HOME on linux?
Running testenv.pl as sudo do not pickup the environment variable JAVA_HOME
value.

$ echo $JAVA_HOME
/home/powah/jdk1.6.0_13

testenv.pl is:
#!/usr/bin/perl
print "begin JAVA_HOME = $JAVA_HOME\n";
$J_HOME = $ENV{'JAVA_HOME'};
print "$ENV{'JAVA_HOME'} JAVA_HOME = $J_HOME\n";

$ perl testenv.pl
begin JAVA_HOME =
/home/powah/jdk1.6.0_13 JAVA_HOME = /home/powah/jdk1.6.0_13

$ sudo perl testenv.pl
begin JAVA_HOME =
JAVA_HOME =

Last edited by powah; 04-22-2009 at 11:18 AM.
 
Old 04-22-2009, 11:22 AM   #2
*******
Member
 
Registered: Feb 2009
Posts: 63

Rep: Reputation: 16
By default Sudo scrubs environment variables. The /etc/sudoers contains examples which ones it keeps by default, which ones you can keep and how to accomplish that.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
creating environment variables in perl iceman_san Linux - Newbie 7 08-11-2007 08:56 PM
Perl: Source shell script to for environment variables? stefanlasiewski Programming 3 02-07-2006 06:27 PM
Bash script environment variables mbjunior99 SUSE / openSUSE 4 12-28-2005 12:40 AM
Environment variables and perl jrbiochem Linux - General 0 05-06-2004 09:40 AM
Environment variables Perl nbp Programming 1 10-28-2003 08:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration