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!

Limit logins to 1 1

Status
Not open for further replies.

tjv

IS-IT--Management
Joined
Sep 19, 2001
Messages
100
Location
US
I found this script on aplawrence.com which is suppose to limit user logins to 1 but it does not work. I put it in the users .profile

I am on SCO 5.0.5

IAM=`who am i | cut -d" " -f1`
COUNT=`w | cut -d" " -f1 | grep "^$IAM$" | wc -l`
[ $COUNT -gt 1 ] && exit 0
 
tried that it didn't work. I get no error messages or anything either.
 
what shell are you using?
I cut and pasted the first 2 lines into a file, removed the second $ and added
echo $COUNT

and it came up with a 1.
 
tjv:

Syntax wise you look OK. Are you sure the output of who am i is actually your userid? You might try whoami of even look at the variable $LOGNAME. You can always set it in /etc/profile if it doesn't exist.

Also try:

w -h -s

this will suppress the heading which might be causing a problem.

Regards,

Ed
 
who am i shows user1 but I did that test with putting in echo and I to returned a value of 1.

olded:
what do you mean by $LOGNAME?
 
tjv:

Most flavors of unix will set the shell variable LOGNAME when you log in. If it doesn't an administrator can place something like:

LOGNAME=`id|sed 's/^uid=[0-9]*(\(.*\)) gid.*/\1/'`

or

LOGNAME=`who am i | cut -d" " -f1`

in /etc/profile

Regards,

Ed
 
You can try this:
Code:
[ `who | grep -c "^$LOGNAME "` -gt 1 ] && exit 0

Hope This Help
PH.
 
PHV that works as I need. Are there any negative impacts on using this script rather than the one I had found.
 
How can I put in a message stating that the user is logged in more than once or something to that affect.
 
Hi:

Ripped out of my /etc/profile:

# all on one line:
[ `w -h -s| cut -d" " -f1 | grep "^$LOGNAME$" | wc -l` -gt 1 ] && { echo "$LOGNAME is logged in more than
once"; exit 0; }
 
tjv, you can try something like this:
Code:
[ `who | grep -c "^$LOGNAME "` -gt 1 ] && {
  who -H | awk 'NR==1 || $1=="'$LOGNAME'" {print}'
  id; echo "$LOGNAME still logged"; exit 0
}

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top