|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
I have a small issue with Bash: I try to run a bash script as a Linux service, exporting one variable to be used in another bash script. Here's the important pieces of the scripts: #!bin/sh # test script # chkconfig 345 86 15 USER1=user1 export VAR1=/opt/test RETVAL=0 start() { su -l $USER1 -c $VAR1/test.sh RETVAL=$? } .... exit $RETVAL So, I registered it as a service in RHEL using chkconfig --add test. See that I call a second script, test.sh, not as root, but as the user1 account. This account has full privileges inside /opt/test directory. In /opt/test/test.sh, I just have one echo, simple line: #!bin/sh echo "VAR1 = $VAR1" But VAR1 is always empty when it's echoed. I never get the /opt/test value. When I modify the su -l line above to .. "$VAR1"/test.sh It works fine this way! Unfortunately, I need to run the service using the user1 credential, not root. So, what am I missing here? Could you me? Thank you very much! |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Mar 20, 3:36pm, wrpas...@gmail.com wrote:
> Hi, > > I have a small issue with Bash: I try to run a bash script as a Linux > service, exporting one variable to be used in another bash script. > Here's the important pieces of the scripts: > > #!bin/sh > # test script > # chkconfig 345 86 15 > > USER1=user1 > export VAR1=/opt/test > RETVAL=0 > > start() { > su -l $USER1 -c $VAR1/test.sh > RETVAL=$?} > > ... > exit $RETVAL > > So, I registered it as a service in RHEL using chkconfig --add test. > See that I call a second script, test.sh, not as root, but as the > user1 account. This account has full privileges inside /opt/test > directory. In /opt/test/test.sh, I just have one echo, simple line: > > #!bin/sh > echo "VAR1 = $VAR1" > > But VAR1 is always empty when it's echoed. I never get the /opt/test > value. > > When I modify the su -l line above to > . "$VAR1"/test.sh > > It works fine this way! Unfortunately, I need to run the service using > the user1 credential, not root. So, what am I missing here? Could you > me? > > Thank you very much! well...you're not *you* any more. you su'd to somebody else with a whole new environment. how about something like: su -l $USER1 -c $VAR1/test.sh $VAR1 so that it passes an argument to the test script and in test.sh: #!/bin/sh VAR1=$1 echo $VAR1 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Hi "OldSchool",
I found a simple solution (how didn't I look at it before?): su has the -m switch, "preserve environment", so the su line can be changed to: su -m $USER1 -c $VAR1/test.sh This way we can call the other script using the user1 account preserving the environment variables. Thanks a lot for your ! On Mar 20, 4:59 pm, OldSchool <scott.my...@macys.com> wrote: > On Mar 20, 3:36 pm, wrpas...@gmail.com wrote: > > > > > Hi, > > > I have a small issue with Bash: I try to run a bash script as a Linux > > service, exporting one variable to be used in another bash script. > > Here's the important pieces of the scripts: > > > #!bin/sh > > # test script > > # chkconfig 345 86 15 > > > USER1=user1 > > export VAR1=/opt/test > > RETVAL=0 > > > start() { > > su -l $USER1 -c $VAR1/test.sh > > RETVAL=$?} > > > ... > > exit $RETVAL > > > So, I registered it as a service in RHEL using chkconfig --add test. > > See that I call a second script, test.sh, not as root, but as the > > user1 account. This account has full privileges inside /opt/test > > directory. In /opt/test/test.sh, I just have one echo, simple line: > > > #!bin/sh > > echo "VAR1 = $VAR1" > > > But VAR1 is always empty when it's echoed. I never get the /opt/test > > value. > > > When I modify the su -l line above to > > . "$VAR1"/test.sh > > > It works fine this way! Unfortunately, I need to run the service using > > the user1 credential, not root. So, what am I missing here? Could you > > me? > > > Thank you very much! > > well...you're not *you* any more. you su'd to somebody else with a > whole new environment. > > how about something like: > > su -l $USER1 -c $VAR1/test.sh $VAR1 > > so that it passes an argument to the test script > > and in test.sh: > #!/bin/sh > VAR1=$1 > echo $VAR1 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Mar 21, 10:36am, wrpas...@gmail.com wrote:
> Hi "OldSchool", > > I found a simple solution (how didn't I look at it before?): su has > the -m switch, "preserve environment", so the su line can be changed > to: > > su -m $USER1 -c $VAR1/test.sh > > This way we can call the other script using the user1 account > preserving the environment variables. > I believe that that's a GNU'ism that may not be portable...... |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
2008-03-21, 08:52(-07), OldSchool:
> On Mar 21, 10:36am, wrpas...@gmail.com wrote: >> Hi "OldSchool", >> >> I found a simple solution (how didn't I look at it before?): su has >> the -m switch, "preserve environment", so the su line can be changed >> to: >> >> su -m $USER1 -c $VAR1/test.sh >> >> This way we can call the other script using the user1 account >> preserving the environment variables. >> > > I believe that that's a GNU'ism that may not be portable...... I think it rather comes from BSD. But it's true that few Unices have it. -- Stéphane |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
In article <slrnfu7o6u.9us.stephane.chazelas@spam.is.invalid> ,
Stephane CHAZELAS <this.address@is.invalid> wrote: .... >> I believe that that's a GNU'ism that may not be portable...... > >I think it rather comes from BSD. But it's true that few Unices >have it. A statement much akin to saying that few PC operating systems support the AllocConsole() function call. It is true that very few do. It is also true that almost every PC OS that matters does. You pay your money; you take your chances. |
|
![]() |
| Outils de la discussion | |
|
|