Unix Technical Forum

little scripting problem

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, ...


Go Back   Unix Technical Forum > Unix Operating Systems > Slackware Linux Support

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-20-2008, 09:05 AM
Darren
 
Posts: n/a
Default little scripting problem

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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-20-2008, 09:06 AM
Menno Duursma
 
Posts: n/a
Default Re: little scripting problem

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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-20-2008, 09:12 AM
Darren
 
Posts: n/a
Default Re: little scripting problem


"Menno Duursma" <pan@desktop.lan> wrote in message
newsan.2005.06.06.11.20.32.177294@desktop.lan...
> 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.
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:42 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com