how to reuse a shell script to change env from perl
Hi:
I am trying to reuse an existing shell script foo1.csh to set environment variables inside a perl script and its childern processes.
Is it possible at all to make those environment variables persistent in the main perl process and its children processes?
Do I have to create a new shell script foo2.csh to call the existing shell script foo1.csh first to set up env before launch the perl script from the new shell script foo2.csh? I am hoping there is a way to do both steps within the perl script.
I do not know for sure, but I think you have design problem. It appears you ported shell script to perl. If you started with n scripts, and it was a good working design, then you should have n perl scripts as well.
If your perl is well-written, it should be using the same ENV variables names each time it runs, probably against different file sets or databases.
A standard trick in designing something like this is to use shell script "include" files.
So you will now have to extract the ENV definitions from n shell files into small ENV only definition scripts.
Then do something like this - assume we have six files names env1 env2 ... env6
I do not know of a way to source a file in perl. Sourcing means that shell runs in the current process context some script. perl and shell are NOT the same language, so you would have to parse a shhell script file for variables, then call putenv for each variable.
You will have to add a subroutine to your perl code to do this, call the sub for each external file to need to "source" then run the rest of the perl code. UNless you have hundreds of external scripts, this may not be worth the effort.
I do not know for sure, but I think you have design problem. It appears you ported shell script to perl. If you started with n scripts, and it was a good working design, then you should have n perl scripts as well.
If your perl is well-written, it should be using the same ENV variables names each time it runs, probably against different file sets or databases.
A standard trick in designing something like this is to use shell script "include" files.
So you will now have to extract the ENV definitions from n shell files into small ENV only definition scripts.
Then do something like this - assume we have six files names env1 env2 ... env6
I do not know of a way to source a file in perl. Sourcing means that shell runs in the current process context some script. perl and shell are NOT the same language, so you would have to parse a shhell script file for variables, then call putenv for each variable.
You will have to add a subroutine to your perl code to do this, call the sub for each external file to need to "source" then run the rest of the perl code. UNless you have hundreds of external scripts, this may not be worth the effort.
[/code]
Hi Jim:
Thanks again for your help.
I am attempting to automate some of our currently manual tasks. We do not have "real" script yet, other than those shell scripts to set ENVs.
Well, I may have to extract them into perl and start from there.
Hello All.
Good Afternoon.
I need one small help regarding setting of env variables for a particular host by getting it from the DB.
For ex :
1. I am using LOCALHOST.
2. When I run a ./hostset.sh it should pick up the Oracle home details from associated DB and set it.
Please... (1 Reply)
hi,
I have a local.conf file which has the first line
TOPDIR = "/home/mvdev/workspace/boxer". I want to replace the value to
"/home/common/workspace/mirror". I tried the following perl command that is
perl -p -i -e 's/Path/path1/g' myfile.txt then
sed... (7 Replies)
Hi
I am trying to write a shell script and wanted to re-use the value which I have entered already.
Here is the sample code.
echo "Enter Value : \c" ; read val
echo "Enter number: $val\c" ; read num
Now I wanted to change the value as showing in 2nd Line or if I will use enter, it... (15 Replies)
greetings,
i have a sh script that calls a python script. the sh script sets an env variable BIN:
export BIN=bin64i need to get that BIN variable's value and use it within this python script. anyone know how to do this? thanx in advance. (5 Replies)
I have 3 programs, 1 in perl, 2 in csh: call them perl1, csh1 and run.ol
I need perl1 to set csh1 variable NOLOG_qsub = ""
I need perl1 to run, run.ol
run.ol takes the executable and input and outputs to output
run.ol#!/bin/csh -f
# run.ol executable input output
perl1 should... (1 Reply)
Hi All,
I have made a file file usercreate.sh & it has to run in tcsh env & needs some path to be set.
my script is as below.
##########################
#!/bin/csh
setenv PATH "/usr/lib/java/class"
setenv LD_LIBRARAY_PATH
###########################
but when i am ruuning my script... (1 Reply)
sdir;csp os_lib-0.5.24;bdir;cbpdob ---enable-useosstl os_lib-0.5.24;mbp os_lib-0.5.24;
If i run this command in unix shell directly it is running.
sdir;csp HA_util-0.0.7;bdir;cbpdob ---enable-useosstl HA_util-0.0.7;mbp HA_util-0.0.7;
HA_util === Configuring source package
HA_util... (4 Replies)
I have a shell script I want to run that will set environment variables based on the value of an input variable submitted when the shell script is called. For example:
$ mgenv.sh prod
This would set environment variables for prod
$ mgenv.sh test
This would set environment variables... (1 Reply)
Hi
I am having a script which sets the application environment. In this script i am sourcing the applications env file, when i am debugging the script i see its executing all the environment values and all the variable values are set properply.
Once this main shell script executes, then... (4 Replies)
Hi,
I am using HP-UNIX.
I have a requirement as below
I have to change env twice like:
cadenv <env>
cadenv <env>
ccm start -d /dbpath
ccm tar -xvf *.tar
ccm rcv ....
mv *.tar BACKUP
but after I do the first cadenv <env> , I am unable to execute any of the later commands .
... (6 Replies)