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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

restrict number of times a user can login 3

Status
Not open for further replies.

dodge20

MIS
Joined
Jan 15, 2003
Messages
1,048
Location
US
I am on Unix sco 5. We have a bunch of people using telnet to login multiple times. I was wondering if there was a way to restrict certain users to allow only 1 login. Any help will be appreciated.

thanks

Dodge20
 
In the user's profile you can try something like this:
Code:
[ `who | grep -c "^$LOGNAME "` -gt 1 ] && {
  who -H | awk 'NR==1 || $1=="'$LOGNAME'" {print}'
  echo "$LOGNAME already connected"
  exit
}

Hope This Help
PH.
 
You will have to forgive me, but I don't spend much time with unix, so I am not very familiar with it.

where is the individual user's profile? Is it the .cshrc or .login?

In the /etc there is a profile, but that isn't for the individual user.



Dodge20
 
I tried it in the .login gave a couple of command not found, then it still logged in. This is what was displayed


You have mail
[: Command not found.
{: Command not found.
jay2 already connected
1%%


Dodge20
 
I guess your login shell is csh, my example is for sh or ksh. Try something like this:
Code:
if ( `who | grep -c "^$LOGNAME "` > 1 ) then
  who -H | awk 'NR==1 || $1=="'$LOGNAME'" {print}'
  echo "$LOGNAME already connected"
  logout
endif

Hope This Help
PH.
 
Thanks it worked. This is a picky issue, but is there a way to delay the logout, because it goes so fast, that you can't see the echo statement.

Thanks again, have a star

Dodge20
 
man sleep

Hope This Help
PH.
 
You can also add


echo Please enter any key to continue
read x


In the user directory be it /u the profile is .profile, and /etc profile is the script executed for all users.

Put the code in /etc for all, or into each to be selective.
 
If you use the sleep command the script will become breakable by Ctrl-C, and the following logout will be avoided.
So you have to use "trap" built-in command in order to intercept malicious Ctrl-C
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top