This is a discussion on little scripting problem within the Slackware Linux Support forums, part of the Unix Operating Systems category; --> hi all. I have a little scripting problem. here's what i've done so far when a user logs in, ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| hi all. I have a little scripting problem. here's what i've done so far when a user logs in, the /etc/profile scripts kicks in and checks if the user is root, it the user isn't root then it mounts an nfs export to /var/spool/mail so the user hass access to global mail addressed to him. when the user logs out the nfs export ius unmounted in .bash_logout that works ok but when i log in as me i may want to su as root. no nfs clients need mounting in fact i need to be able to check if i am logged into root via su ot via direct login. How do i do this? Thanks |
| |||
| On Mon, 06 Jun 2005 10:32:00 +0000, Darren wrote: > in fact i need to be able to check if i am logged into root via su ot via > direct login. How do i do this? Well with "direct login" your shell is a child of init, hence: if [ "$PPID" -eq "1" ]; then echo yep else echo nope fi However this catches any sub-shell (even if "-l" such as Xterm) as not a direct login shell. If you only want to differentiate between "su" or not, maybe something like: TTY=`tty` if [ "`ls -l "$TTY" |awk '{print $3}'`" == "$USER" ]; then echo nope else echo yep fi -- -Menno. |
| ||||
| "Menno Duursma" <pan@desktop.lan> wrote in message news > On Mon, 06 Jun 2005 10:32:00 +0000, Darren wrote: > > > in fact i need to be able to check if i am logged into root via su ot via > > direct login. How do i do this? > > Well with "direct login" your shell is a child of init, hence: > > if [ "$PPID" -eq "1" ]; then > echo yep > else > echo nope > fi > > However this catches any sub-shell (even if "-l" such as Xterm) as not a > direct login shell. If you only want to differentiate between "su" or not, > maybe something like: the first one failed because even in s script it spawned a new instants of the shell. I recall seeing something that was supposed to be able to run scripts under the existing shell.. I can't remember where though > > TTY=`tty` > if [ "`ls -l "$TTY" |awk '{print $3}'`" == "$USER" ]; then > echo nope > else > echo yep > fi > that one did the trick. Thanks > -- > -Menno. > |