How to set gobal enviroment vaibles in HPUNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to set gobal enviroment vaibles in HPUNIX
# 1  
Old 12-18-2008
How to set gobal enviroment vaibles in HPUNIX

Hi ,

I have one script setting envrioments varaible , calling this scripts in another script,i wnat to user thoese envrioemnt variables in parent script.

I am trying set envrioment variables with "export" comand i am unable to access thoese envrioment variables.

Code:
$ cat dm_env21
DM_TK_DB=MICDEV1B;export DM_TK_DB
test=SVWMIG1B;export test
echo $?
echo $DM_TK_DB

I want DM_TK_DB,test varibles in test.sh scripts

Code:
$ cat test.sh
#!/bin/ksh
sudo su - micdev1b << EOF
cd /m61/micdev1b/work/dm/scripts
. /m61/micdev1b/work/dm/scripts/dm_env21
echo $?
#echo $DM_TK_DB
echo $test
EOF

I am runing test.sh with my user and i have sudo permission on micdev1b.

I am runing tihs test.sh script i am getting DM_TK_DB,test variable contains null values.

Could u please help me.

Last edited by bakunin; 12-18-2008 at 06:30 AM.. Reason: added code-tags to the code
# 2  
Old 12-18-2008
use the "-c" switch of su to execute commands. Even then i suppose that using sudo, su AND a here-document in one line might be too much for the shell to parse.

Try it the following way:

Code:
sudo su - <user> -c <script>

Where <script> contains the here-document. If nothing else this will at least make it easier to find out where the problem really is.

I hope this helps.

bakunin
# 3  
Old 12-22-2008
Quote:
Originally Posted by bakunin
use the "-c" switch of su to execute commands. Even then i suppose that using sudo, su AND a here-document in one line might be too much for the shell to parse.

Try it the following way:

Code:
sudo su - <user> -c <script>

Where <script> contains the here-document. If nothing else this will at least make it easier to find out where the problem really is.

I hope this helps.

bakunin
if we want run script with sudo su - <user> -c <script>[/code] this scname should added into sudo configration files(i am not sure file name).

$ sudo su - micdev1b -c /m61/micdev1b/work/dm/scripts/run_dms70_10_atai_dbanalyze.sh
Sorry, user rsiddaba is not allowed to execute '/usr/bin/su - micdev1b -c /m61/micdev1b/work/dm/scripts/run_dms70_10_atai_dbanalyze.sh' as root on ducati.
# 4  
Old 12-22-2008
Quote:
Originally Posted by ramakoti.s
Hi ,

I have one script setting envrioments varaible , calling this scripts in another script,i wnat to user thoese envrioemnt variables in parent script.

I am trying set envrioment variables with "export" comand i am unable to access thoese envrioment variables.

Code:
$ cat dm_env21
DM_TK_DB=MICDEV1B;export DM_TK_DB
test=SVWMIG1B;export test
echo $?
echo $DM_TK_DB

I want DM_TK_DB,test varibles in test.sh scripts

Code:
$ cat test.sh
#!/bin/ksh
sudo su - micdev1b << EOF
cd /m61/micdev1b/work/dm/scripts
. /m61/micdev1b/work/dm/scripts/dm_env21
echo $?
#echo $DM_TK_DB
echo $test
EOF

I am runing test.sh with my user and i have sudo permission on micdev1b.

I am runing tihs test.sh script i am getting DM_TK_DB,test variable contains null values.

Could u please help me.

Hello ramakoti,


Try the following.

When you use the command su - (user_name) you are change the variable for the next user_name.
Try the command without the "-"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question about enviroment variable.

Hi Gurus, I am stuck on below issue. in my .profile. I have two variable: x=abc$123 t=xyz$ when running env command, I got below: x=abc t=xyz$ my OS is SunOS 5.10 sun4v sparc SUNW,SPARC-Enterprise-T5220 I am wondering why t=xyz$ shows exactly value? I try below: (9 Replies)
Discussion started by: ken6503
9 Replies

2. Shell Programming and Scripting

Killing all the process of a particular enviroment

Hi Folks, I have the below command that will kill all the process of an environment, lets say if I have reached to the location cont directory under which I want to kill multiple process so the command will be .... kill -9 `ps -ef | grep cont | grep -v grep | awk '{print $2}'` Now please... (4 Replies)
Discussion started by: punpun66
4 Replies

3. Solaris

Save enviroment variables

I need to save my enviroment variables,specially the $PATH.When I put it on .cshrc at next reboot I lost the configuration.How can avoid this?Thanks (2 Replies)
Discussion started by: bgf0
2 Replies

4. Shell Programming and Scripting

enviroment settings

What are the environment setting during a cron session? I have HP-UX and I want to send the output/file from a script to several e-mail addresses. I want to create an env-var to store the e-mail addresses in my .profile, but I do not know if it will be visible when a script is executed in a cron. (4 Replies)
Discussion started by: ALTRUNVRSOFLN
4 Replies

5. UNIX for Dummies Questions & Answers

dos2unix equivalent in hpunix

hi, what is the dos2unix equivalent in hpunix ?? (10 Replies)
Discussion started by: risshanth
10 Replies

6. Shell Programming and Scripting

Enviroment Differences script(s)

Im looking for any sample scripts that would output a current environment setup to a file and possibly then take 2 files and list any differences This will allow us to quickly see any differences between environments in case of issue? At a high level this would take Unix Kernel Params,... (2 Replies)
Discussion started by: JoeShmoe
2 Replies

7. Solaris

set enviroment variable..

Hello... I was wondering can anyone explain me how to set up enviroment variable to be permanent... I tryed with setenv but my solaris does not have this command... then I did: export ORACLE_SID=base1 export ORACLE_BASE=/home export ORACLE_HOME=$ORACLE_BASE/oracle/8.1.6 and by... (5 Replies)
Discussion started by: amon
5 Replies

8. UNIX for Dummies Questions & Answers

Enviroment variables...

Hi guys, thanks in advance for this easy answer.... :s Ok I am trying to output the enviroment varable for host in Solaris. I have tried $HOST, $HOST_NAME, $HOSTNAME carn't find it anywhere, does someone want to put me out of my misary and tell me what it is??? :confused: :eek: Thanks... (2 Replies)
Discussion started by: B14speedfreak
2 Replies

9. UNIX for Dummies Questions & Answers

Help! - How do I compile C++ in UNIX Enviroment?

:confused: Hi, does anyone here know how to compile and run C++ in UNIX environment? I am so desperate! Any help is greatly appreciated. Thanks! (3 Replies)
Discussion started by: Kahuashi
3 Replies

10. HP-UX

on hpunix cpu usage fields

i have found a structure contained in file global _pstat_body.h at the path /usr/include/sys/pstat which is named __pst_dynamic . A field by name psd_cpu_time is an array of maximum cpu states the kernel supports . i,e psd_cpu_time specify all the cpu timings in an array... (8 Replies)
Discussion started by: vish_shan
8 Replies
Login or Register to Ask a Question