Identifying .login Shells

Maarten Litmaath maart at cs.vu.nl
Tue Feb 14 11:26:32 AEST 1989


#! /bin/sh
# @(#)loginsh 2.0 89/02/14 Maarten Litmaath @ VU Amsterdam (maart at cs.vu.nl)
#
# determine if the parent is a loginshell: if it is either a child of
# /etc/init (process id 1), or /usr/etc/in.rlogind or /etc/rlogind
# (note: it's unsafe to assume the parent is a loginshell iff (sic) its name
# starts with a `-')
# note: loginsh is BSD-specific; a SysV variant should be straightforward
# if invoked with any argument, loginsh will produce some diagnostics

# first find out if `sps' (the fast variant of `ps') exists - if you already
# know the answer, you could replace the test either by the `sps' or the `ps'
# assignments
# close stderr, to prevent complaints from sh if `sps' doesn't exist

exec 2>&-

[ "`sps N`" ] && {
	PPS='sps fp '
	PS='sps p '
	S=
} || {
	PPS='/bin/ps l'
	PS='/bin/ps '
	S=..
}

PSED="sed -n '2s/................. *\([^ ]*\).*/\1/p'"
SED="sed -n '2s/$S..................\([^ ]*\).*/\1/p'"

ppid=`$PPS$$ | eval $PSED`

[ $# != 0 ] && /bin/echo -n "my ppid is $ppid, of which the ppid is "

ppid=`$PPS$ppid | eval $PSED`

[ $ppid = 1 ] && {
	[ $# != 0 ] && echo "1: init"
	exit 0
}

cmd=`$PS$ppid | eval $SED`

[ $# != 0 ] && echo "$ppid: $cmd"

case "$cmd" in
	in.rlogind|rlogind)
		exit 0
esac

exit 1
-- 
 "I love it                            |Maarten Litmaath @ VU Amsterdam:
          when a plan comes together." |maart at cs.vu.nl, mcvax!botter!maart



More information about the Comp.unix.questions mailing list