How to execute script with all environment varialbes set for particular user using "su -c" command?

Hello All,

Does anybody know how “su -c ‘/opt/test/bin/testreport -a’ - testadmin >$OUTTESTDIR/test.txt 2>>$LOGFILE” could correctly be executed in SUSE linux?
Right now i have troubles with reading user environment variables of “testadmin” user, somehow it doesn’t work for me. In RH linux it works without problems, all testadmin environment variables are read while executing “/opt/test/bin/testreport” script.

sigw09-mco3:~ # uname -a
Linux sigw09-mco3 2.6.18.2-34-default #1 SMP Mon Nov 27 11:46:27 UTC 2006 x86_64 x86_64 x86_64 GNU/Linux
sigw09-mco3:~ #
sigw09-mco3:/etc # cat SuSE-release
openSUSE 10.2 (X86-64)
VERSION = 9.2
sigw09-mco3:/etc #
sigw09-mco3:~ # echo $SHELL
/bin/bash
sigw09-mco3:~ #
sigw09-mco3:~ # bash --version
GNU bash, version 3.1.17(1)-release (x86_64-suse-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
sigw09-mco3:~ #

Note: system where it works
[root@sigw09-mco2 ~]# bash --version
bash --version
GNU bash, version 3.00.15(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2004 Free Software Foundation, Inc.
echo -ne “\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007”
[root@sigw09-mco2 ~]#

thank you many times!
regards
Pavel

On 2010-10-20 17:36, zakp wrote:

> sigw09-mco3:/etc # cat SuSE-release
> openSUSE 10.2 (X86-64)
> VERSION = 9.2

You have an inconsistent system. Both lines should show the same number - and any of the two are
obsolete. You have to upgrade the entire system.


Cheers / Saludos,

Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)

Could someone please run this simple test in SUSE environment and let me know whether it works as expected or not? thank you…

RH
[root@sigw09-mco2 ~]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),20000(mco)
[root@sigw09-mco2 ~]#
[root@sigw09-mco2 ~]# su -c ‘/home/zakp/testrun’ - zakp
zakpenv
[root@sigw09-mco2 ~]# su -c ‘/home/zakp/testrun’ zakp

[root@sigw09-mco2 ~]# cat /home/zakp/testrun
echo $ZAKPENV
[root@sigw09-mco2 ~]# cat /home/zakp/.kshrc
export ZAKPENV=zakpenv
[root@sigw09-mco2 ~]#

SUSE
sigw09-mco3:/home # id
uid=0(root) gid=0(root) groups=0(root),100(users),1400(mco)
sigw09-mco3:/home #
sigw09-mco3:/home # su -c ‘/home/zakp/testrun’ - zakp

sigw09-mco3:/home # su -c ‘/home/zakp/testrun’ zakp

sigw09-mco3:/home # cat /home/zakp/testrun
echo $ZAKPENV
sigw09-mco3:/home # cat /home/zakp/.kshrc
export ZAKPENV=zakpenv
sigw09-mco3:/home #

On 2010-10-27 12:36, zakp wrote:

> sigw09-mco3:/home # cat /home/zakp/testrun
> echo $ZAKPENV

Notice that your script doesn’t have the shebang, so it should run by default with bash on a suse
system, not kshell, as you seem to indicate by your next paragraph.

> sigw09-mco3:/home # cat /home/zakp/.kshrc
> export ZAKPENV=zakpenv
> sigw09-mco3:/home #

I mean, this will not affect your script above. It will not have that variable.


Cheers / Saludos,

Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)