User Login Limit


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting User Login Limit
# 1  
Old 06-07-2005
Tools User Login Limit

Gud day Smilie

We have a limited user login so we want to restrict 1 login per user. We have added below script in each user's profile but it is not working Smilie , I displayed the output for COUNT (by inserting echo command) but the value is always 1. Hope you could help me.

Thanks Smilie


IAM=`who am i | cut -d" " -f1`
COUNT=`w | cut -d" " -f1 | grep "^$IAM$" | wc -l`
[ $COUNT -gt 1 ] && exit 0
# 2  
Old 06-07-2005
Try using output from the last command
Code:
 last | grep jmc | head
jmcnama  pts/16       Tue Jun  7 08:14   still logged in
jmcnama  pts/7        Mon Jun  6 11:18 - 19:05  (07:46)
jmcnama  pts/7        Mon Jun  6 08:14 - 11:18  (03:03)
jmcnama  pts/3        Fri Jun  3 07:41 - 20:15  (12:33)
jmcnama  pts/16       Thu Jun  2 08:17 - 16:27  (08:09)
jmcnama  pts/11       Wed Jun  1 07:42 - 20:15  (12:32)
jmcnama  pts/3        Fri May 27 07:31 - 14:44  (07:12)
jmcnama  pts/30       Thu May 26 08:26 - 20:39  (12:12)
jmcnama  pts/21       Wed May 25 08:28 - 20:12  (11:43)
jmcnama  pts/38       Tue May 24 13:04 - 13:11  (00:07)

You can detect multiple logins with something like this:
Code:
login_count= `last | grep $USER | awk '
        BEGIN{count=0} { if (index($0,"still logged")>0) { count++}} END{print count}'`

# 3  
Old 06-07-2005
Here is what I do :


Code:
name=`echo $LOGNAME,`
sessactive=`who | awk '{printf",%s,\n",$1}' | grep ,$LOGNAME, | wc -l`

And then you'll know how many session that user has...and I guess you know what to do next.

I have change my code a month ago because that did not give me the correct count. Sometime users had some other jobs running as phantom but no session open, we have a Universe database and I had to modify my code such as :

Code:
 
sessactive=`ps -ef | grep /uv/bin/uv | awk '{printf",%s,\n",$1}' | grep ,$LOGNAME, | wc -l`

Now it is working better.
Hope it helps.
# 4  
Old 06-07-2005
hi ~*

The script worked perfectly fine.
thanks for the help Smilie


Quote:
Originally Posted by qfwfq
Here is what I do :


Code:
name=`echo $LOGNAME,`
sessactive=`who | awk '{printf",%s,\n",$1}' | grep ,$LOGNAME, | wc -l`

And then you'll know how many session that user has...and I guess you know what to do next.

I have change my code a month ago because that did not give me the correct count. Sometime users had some other jobs running as phantom but no session open, we have a Universe database and I had to modify my code such as :

Code:
 
sessactive=`ps -ef | grep /uv/bin/uv | awk '{printf",%s,\n",$1}' | grep ,$LOGNAME, | wc -l`

Now it is working better.
Hope it helps.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

User Account Login Login on your AIX server

I want to learn AIX. I would like to find someone who would be willing to give me a login to their AIX home lab server. My intent is to poke around and discover the similarities and differences of AIX compared to other *NIXs. I am a UNIX admin so I can think of what some immediate concerns may... (1 Reply)
Discussion started by: perl_in_my_shel
1 Replies

2. Shell Programming and Scripting

Limit a user's login prompt upon logon

Hey Am new to scripting in aix 5.3 I need to write a script to limit a user's logon prompt to an interactive menu based upon logon and nothing else. Any ideas much appreciated. :wall: (4 Replies)
Discussion started by: mills
4 Replies

3. AIX

Limit a user on AIX

Hello, Sorry for my poor English. I have to reduce rights for a user on AIX system so that: When he does , he find in output, only filesystems on which he has permissions .He can't do to change user. Very thanks for helping. (2 Replies)
Discussion started by: edosseh
2 Replies

4. AIX

Limit user access

We have gotten an application that will read and display logs in a report format. The application need a user name and password to access the AIX servers where the logs reside. My problem is the logs are in a few different file systems on the server. Is there any way to lock the user to only the... (1 Reply)
Discussion started by: daveisme
1 Replies

5. Solaris

error message rmclomv ... SC Login Failure for user Please login:

Hello World ~ HW : SUN Fire V240 OS : Solaris 8 Error message prompts 'rmclomv ... SC login failure ...' on terminal. and Error Message prompts continually 'SC Login Failure for user Please login:' on Single Mode(init S) The System is in normal operation, though In case of rain, Can... (1 Reply)
Discussion started by: lifegeek
1 Replies

6. Red Hat

limit non login id for ftp

Hi All, How can I limit a userid (/bin/false) to have access only to ftp service? On redhat ent 4. Thanks! (1 Reply)
Discussion started by: itik
1 Replies

7. Linux

Linux user limit?

Hi All, I did a search of the forum on this but I could only find answers for UNIX flavours. Are there any limits on the amount of users you can have on a linux box? Have the likes of Red Hat introduced any license limits or is it just constrained by system parameters like ulimit max user... (0 Replies)
Discussion started by: pondlife
0 Replies

8. UNIX for Dummies Questions & Answers

Error, Login Limit Exceeded by 1 user

Would appreciate some help, system was displaying an error regarding the kernal when a "sar" was run, after a reboot we get "WARNING user login limit exceeded by 1 user". We have plenty of licences. any ideas? (1 Reply)
Discussion started by: nchrocc
1 Replies

9. AIX

failed login time limit

Hello, we had a situation where an account was locked out due to too many failed login attempts. From the logs (failedlogin, etc) it appears that AIX 'remembered' the failed login attempts from the past month or so. does anyone know where this is set, or how long it will remember the number of... (2 Replies)
Discussion started by: zuessh
2 Replies

10. UNIX for Dummies Questions & Answers

Limit login time...

How do I limit the amount of idle time an account gets on solaris? Thanks. VJ (2 Replies)
Discussion started by: vancouver_joe
2 Replies
Login or Register to Ask a Question