Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to source shell scripts in a cgi script 1

Status
Not open for further replies.

azzazzello

Technical User
Jan 25, 2005
297
US
Greetings,

I have several perl modules which rely on certain environment variables. Those variables can be set with one of the following scripts

Code:
. /source/production_sys.sh
. /source/dev_sys.sh
. /source/another_sys.sh

It is undesirable to manually set environment variables - one must call one of those scripts to set them appropriately.

When I run perl scripts by hand - no problem. I write a bash wrapper that sets the system and runs the perl script.

I do not, however, have that luxury in a cgi script. Is there a way I can get to those environment-setting shell scripts from the cgi script? Because right now, I have a wrapper cgi script that, in backticks, sources the sh file and runs "perl -w script.pl" (in the same backticks). This is just ugly...is there a better way?

Thank you!
 
Can't the Perl script itself do that?

Code:
#!/usr/bin/perl -w

system("/bin/bash whatever.sh");

use Data::Dumper;
use CGI::Carp "fatalsToBrowser";
die Dumper(\%ENV);

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
AFAIK, calling those with system will create the environment, but the environment ceases when the script exits

I think the best way is to write perl equivalents to create the environment variables within the script and require those scripts.

Have a look at
particularly Win32::EnvProcess and Shell::EnvImporter

HTH

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Paul,

Thanks for the tip. For some reason, I did not even think about the idea that there just might be *gasp* ALREADY a module to do it ;). It's not a standard module, so getting it in my environment is not trivial, but that's another story.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top