1838606 Members
2761 Online
110128 Solutions
New Discussion

Unix Script

 
SOLVED
Go to solution
Mario Edgardo
Occasional Contributor

Unix Script

The users know that they only have permission to have only one session open, but they often try to access to a second session, and in order to follow the restriction that we have for them to have only one session open we need a script that kill the old session when they open a second session. The user know that if they try to enter a second time, the old session will be kill, we had this script, but the information has been lost, because the tape that contains the backup of that script was damaged.

Please give us an scriot to try to do that
Regards
Mario
9 REPLIES 9
Jean-Louis Phelix
Honored Contributor
Solution

Re: Unix Script

Hi,

Try to have a look to 'man security'. You will se how to set "NUMBER_OF_LOGINS_ALLOWED" in /etc/default/security to limit multiple logins of the same user.

Regards.
It works for me (© Bill McNAMARA ...)
Mark Grant
Honored Contributor

Re: Unix Script

how about putting this in the /etc/profile

[ `who | grep $LOGNAME | wc -l` -gt 1 ] && {
echo "You are already logged in"
exit
}
Never preceed any demonstration with anything more predictive than "watch this"
Elmar P. Kolkman
Honored Contributor

Re: Unix Script

That would do the opposite: not allowing a second login.

This same question has been asked before, see:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=291677

You'll find your solution there.
Every problem has at least one solution. Only some solutions are harder to find.
Mark Grant
Honored Contributor

Re: Unix Script

You're right Elmar, I didn't read that question right!

Seems an odd thing to do, kill off an old session because you log in again!
Never preceed any demonstration with anything more predictive than "watch this"
John Carr_2
Honored Contributor

Re: Unix Script

Hi

if you script to kill the first session off when a new one opens yopu may terminate a program doing some important work far better to stop multiple login rather than killing old logins.

:-) John.
Elmar P. Kolkman
Honored Contributor

Re: Unix Script

Perhaps this thread is a better solution for your problem, though I too find it strange to kill of old sessions instead of disallowing the extra logins...

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=303607

(This last thread matches your question better then the previous one... The previous one did the same Mark and Philipe do in their solutions...)
Every problem has at least one solution. Only some solutions are harder to find.
Todd McDaniel_1
Honored Contributor

Re: Unix Script

I must say I like Mark's solution.

It is simple and can be modified to allow additional connections if you choose.

And it doesn't kill the existing one that may be running a job, only prevents additional connections.
Unix, the other white meat.
Todd McDaniel_1
Honored Contributor

Re: Unix Script

No points here... I will post from the manpage for security...

NUMBER_OF_LOGINS_ALLOWED
This parameter controls the number of logins allowed
per user. This is applicable only for non-root users.

NUMBER_OF_LOGINS_ALLOWED=0 #Any number of logins are
allowed per user.

NUMBER_OF_LOGINS_ALLOWED=N #N number of logins are
allowed per user.

Default value: NUMBER_OF_LOGINS_ALLOWED=0
Unix, the other white meat.
Roboz
Frequent Advisor

Re: Unix Script

Hello there.
Just a little comment.
the NUMBER_OF_LOGINS_ALLOWED=1 paramenter in the /etc/default/security solutoion proposed will work fine... but not in the CDE environment. CDE will allow multiple logins.
A beter solution is tho restrict the access to users via script as discused.