View Single Post

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

Reply With Quote