1758643 Members
2322 Online
108874 Solutions
New Discussion юеВ

Script Help

 
SOLVED
Go to solution
Nick D'Angelo
Super Advisor

Script Help

I am looking for a script that keep track of the number of users that are currently logged on and will restrict logins to a maximum of 32.

Ie, our application can only have 32 users but we are lacking the tool to restrict this within the application at this time.

Once the 32 user count is hit, then send an email message to the user and also record the login attempt in a log file under /tmp.

Lastly, there will be a two users that should be exempt from this, ie the two sys admins.

Can anyone help me with this?

Thank you,
Always learning
7 REPLIES 7
Jordan Bean
Honored Contributor

Re: Script Help


Easiest solution:
Add this to /etc/profile:

if [ $(id -u) -ne 0 -a $(users | sed 's/root//g' | wc -c) -gt 32 ]; then exit 1; fi

I'm sure of the equivalent for CSH in /etc/csh.login, so I'll let others work that out.


Another solution is to reconfigure the kernel by reducing npty.

You should also concider restricting how many times each user may be logged in by defining NUMBER_OF_LOGINS_ALLOWED=5 in /etc/default/security.



Jordan Bean
Honored Contributor

Re: Script Help

Typo. I'm NOT sure of the CSH variant.
Nick D'Angelo
Super Advisor

Re: Script Help

Thanks for the script, however, it limits all logins and it does not check to see if the minimum has been met yet.
Always learning
Jordan Bean
Honored Contributor

Re: Script Help


Sorry... I'm working on that part... Having a little trouble with regular expressions in sed...

Jordan Bean
Honored Contributor
Solution

Re: Script Help


Okay, sorry about the wait. Try the attached snippet for /etc/profile.

Make sure your admins are part of the group adm (or any other that you specify) so that they are excluded from the user count. Also, root bypasses this check and is excluded from the count as well.

Leif Halvarsson_2
Honored Contributor

Re: Script Help

Hi
A question.
Does the users actually log in on this host and start the application with a command or is it some kind of client-server application. In the later case is the user not realy logged in to the host and tracking users logged in will perhaps not work.

Another idea could be to check how many instances of the application is running before starting a new
if ['ps -ef |grep |wc -l' -gt 32 ]
then
"do something (logout for example)"
else
app_start
fi
Nick D'Angelo
Super Advisor

Re: Script Help

Jordan, works very well - thanks again.

Cheers,

Nickd
Always learning