First of all thanks to the community for interest and several proposed
solutions.
The suggestion received from Hubert based on cmd 'logname' could be
an easy way to solve my problem.
For example in case I logged on with userid it32673 and I'm in 'su
-' , the contents of '$USER' is different of item returned from
'logname' :
lx1iard0:~ # echo $USER
root
lx1iard0:~ # logname
it32673
Then :
- at login the /etc/profile.d/profile_local.sh launch script_xxx
- script_xxxx will compare data received from 'logname' with
'$USER' and it can decide if to continue or terminate...
In conclusion the problem was :
The 'script_xxx' executed at login writes some info about Linux,
zVM and HW based on /proc/sysinfo and zVM CP cmd.
I discovered that someone created scripts that includes commands like
: "su - root -c 'which sudo | grep .........' "
In these cases executing 'su - ...' the 'profile.local' is executed
and 'script_xxx' too, when launch 'which sudo' the 'grep' receive
unpredictable messages not what you expect. It is not good.... :-(( ....
because the execution 'script_xxx' must be transparent for all.
Ciaoo..Thanks again.
Cordiali saluti / Best regards
Marco Bosisio
IBM Italia S.p.A.
Hubert Kleinmanns <[email protected]>
Sent by: Linux on 390 Port <[email protected]>
04/03/2009 09.00
Please respond to
Linux on 390 Port <[email protected]>
To
[email protected]
cc
Subject
Re: Which user env. variable tell me that it is in "s u - " mode ?
Mario,
I fear, I misunderstood your question (or you misunderstood my answer ;-)
)
"echo $SHLVL" returns always "1" after a "su - ...", but another value
after a "su ..." (without th dash). I thought, this was what you would
like to see.
There are several mechanism, to distinguish between the primary login
shell and a "su ..." shell:
1. "ps -f"
$ ps -f
UID PID PPID C STIME TTY TIME CMD
hubert 8163 8162 0 06:58 pts/2 00:00:00 -bash
hubert 23237 8163 0 08:54 pts/2 00:00:00 ps -f
$ su - root
# ps -f
UID PID PPID C STIME TTY TIME CMD
root 23567 8163 0 08:56 pts/2 00:00:00 /bin/su -
root 23569 23567 1 08:56 pts/2 00:00:00 -bash
root 23602 23569 0 08:56 pts/2 00:00:00 ps -f
2. "logname" vs. "id"
# logname
hubert
# id
uid=0(root) gid=0(root) groups=0(root)
Hope this helps.
Regards
Hubert
> -----Ursprüngliche Nachricht-----
> Von: "Marco Bosisio" <[email protected]>
> Gesendet: 03.03.09 14:00:17
> An: [email protected]
> Betreff: Re: Which user env. variable tell me that it is in "s u - "
mode ?
> Hi Hubert,
> your suggestion works fine running for nested scripts, I created 3
> script testa -> testb -> testc like this :
>
> lx1iard0:~ # cat testa
> #!/bin/bash
> echo "testa => SHLVL="$SHLVL
> sh /root/testb
> exit
>
>
> lx1iard0:~ # echo $SHLVL
> 1
>
> lx1iard0:~ # sh testa
> testa => SHLVL=2
> --testb => SHLVL=3
> ----testc => SHLVL=4
>
>
> But.... the variable $SHLVL is always 1 after a "su - " :
>
> it32...@lx1iard0:~> echo $SHLVL
> 1
> it32...@lx1iard0:~> su -
> Password:
> lx1iard0:~ # echo $SHLVL
> 1
> lx1iard0:~ #
>
>
> I customized the profile.local and it launch a script_xxx at login. When
> use 'su - ' I would like that the new user does not execute the
> script_xxx again.
>
>
> Cordiali saluti / Best regards
>
> Marco Bosisio IBM Italia S.p.A.
>
>
>
>
>
>
>
> Hubert Kleinmanns <[email protected]>
> Sent by: Linux on 390 Port <[email protected]>
> 03/03/2009 11.32
> Please respond to
> Linux on 390 Port <[email protected]>
>
>
> To
> [email protected]
> cc
>
> Subject
> Re: Which user env. variable tell me that it is in "s u - " mode ?
>
>
>
>
>
>
> Hi Marco,
>
> try:
>
> echo $SHLVL
>
> The value is incremented for each new sub shell - so it will be "1" for
> login shells (which you get with "su - ..."
>
> Regards
> Hubert
>
>
> > -----Ursprüngliche Nachricht-----
> > Von: "Marco Bosisio" <[email protected]>
> > Gesendet: 03.03.09 11:12:04
> > An: [email protected]
> > Betreff: Which user env. variable tell me that it is in "su - " mode
> ?
>
>
> > Hi,
> > do you know wich user environment variable I have to test
(executing
> > a bash script) to know when I am in "su -" (switch user mode)
?
> >
> >
> > Reading variables provided by "env" command then testing $TERM
I
> > am able to know if not a Linux terminal :
> > ..
> > .......
> > # We can only execute on a terminal SSH / Telnet , not executed if
> > secondary console Linux/zVM
> > if [[ "$TERM" != "xterm" ]] ; then exit
> > fi
> > ......
> >
> > I would like to do the same when the script is executed in a user
> > logged in "su - " mode...
> >
> > Thanks in advance.
> >
> > Cordiali saluti / Best regards
> >
> > Marco Bosisio IBM Italia S.p.A.
> >
> > ----------------------------------------------------------------------
> > For LINUX-390 subscribe / signoff / archive access instructions,
> > send email to [email protected] with the message: INFO LINUX-390
or
> visit
> > http://www.marist.edu/htbin/wlvindex?LINUX-390
> >
>
> --
> Hubert Kleinmanns
> Beratung / Schulung / Projektleitung
>
> Chairman der WG "WebSphere MQ and Business Integration" in der GSE,
deutsche Region.
>
> Tel.: +49 (0) 60 78 / 7 12 21
> Fax: +49 (0) 60 78 / 7 12 25
> Mobil: +49 (0) 178 / 6 97 22 54
> Web: www.kleinmanns.eu
> GSE: www.gsenet.de
>
> ----------------------------------------------------------------------
> For LINUX-390 subscribe / signoff / archive access instructions,
> send email to [email protected] with the message: INFO LINUX-390 or
> visit
> http://www.marist.edu/htbin/wlvindex?LINUX-390
>
>
>
> IBM Italia S.p.A.
> Sede Legale: Circonvallazione Idroscalo - 20090 Segrate (MI)
> Cap. Soc. euro 400.001.359
> C. F. e Reg. Imprese MI 01442240030 - Partita IVA 10914660153
> Società soggetta all?attività di direzione e coordinamento di
> International Business Machines Corporation
>
> (Salvo che sia diversamente indicato sopra / Unless stated otherwise
> above)
>
> ----------------------------------------------------------------------
> For LINUX-390 subscribe / signoff / archive access instructions,
> send email to [email protected] with the message: INFO LINUX-390 or
visit
> http://www.marist.edu/htbin/wlvindex?LINUX-390
>
--
Hubert Kleinmanns
Beratung / Schulung / Projektleitung
Chairman der WG "WebSphere MQ and Business Integration" in der GSE, deutsche
Region.
Tel.: +49 (0) 60 78 / 7 12 21
Fax: +49 (0) 60 78 / 7 12 25
Mobil: +49 (0) 178 / 6 97 22 54
Web: www.kleinmanns.eu
GSE: www.gsenet.de
----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO LINUX-390 or
visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
IBM Italia S.p.A.
Sede Legale: Circonvallazione Idroscalo - 20090 Segrate (MI)
Cap. Soc. euro 400.001.359
C. F. e Reg. Imprese MI 01442240030 - Partita IVA 10914660153
Società soggetta all?attività di direzione e coordinamento di
International Business Machines Corporation
(Salvo che sia diversamente indicato sopra / Unless stated otherwise
above)
----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390