Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiple logins

Status
Not open for further replies.

kporeddy

IS-IT--Management
Joined
Sep 7, 2001
Messages
49
Location
US
Hi
Can any one help me, how to Restrict the multiple logins on the system.

Thanks in advance

Karan
 
If each machine has an /etc/passwd, you can use /usr/bin/false as the users default shell to prevent a particular user from logging in. Ian

"IF" is not a word it's a way of life
 
I'm not sure exactly what's required, but to restrict multiple logins you could add an entry at the start of the user's .profile to check a listing of ps -ef to find out whether there's a current session already on the machine. Something like:

ps -ef | grep $LOGNAME
if [ $? = 0 ]
then
echo "Multiple logins not allowed"
exit
else
......normal login script......
fi

Not sure if this will work as I've not got access to my machine at the moment. If not, I'll get back to you tomorrow. HTH.
 
Thinking about this again, the previous response probably won't work as it will constantly pick up your current session and therefore not allow login. Onsecond thoughts, therefore, you probably need to set a count variable to check whether the number of $LOGNAME 's is greater than 1. Something along the lines of:

usercount=`ps -ef | grep $LOGNAME | wc -l`
if [ $usercount -gt 1 ]
then
echo "Multiple logins not allowed"
exit
else
......normal login script......
fi

Any other ideas gratefully received! Cheers.

 
And another thing....

You'll probably want to change:

usercount=`ps -ef | grep $LOGNAME | wc -l`

to:

usercount=`ps -ef | grep $LOGNAME | grep -v ps | grep -v grep | grep -v wc | wc -l`

to make sure you're not picking up the processes from this command itself! Fun this isn't it? HTH.
 
Hi Ken , ianf

Thanks for your help.

Thanks
Karan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top