Script for viwing the max users and session

hi
i need a script that when a user log in the system , the system knows about the number of session that used by this user and if the number of user sessions are more than MAXSESSION (number that admin define) ,then the system doesn't let the user to log in to the system and write a message on screen about the maximum session.
In the real in need a script to get 2 args(username , max-count)
and when a user who wants to log in , it check it with these 2 args and if the user's session >= max-count then that user can't log in.
-- regards sophia

I found that in the /etc/security the file with the name limits.conf has a feature with the name maxlogins that it's the max number of logins for a given user.
can i use it for login limitation and the other question what is the same file in SCO.
I saw the /etc/security of SCO unix there are some directory of users and roles .

Jalal is right. Doing this in individual profiles is impossible to maintain. Apart from anything else, any user can comment out the check. Even novices can find out how to do that in a forum, probably quite dangerously.

I think the reason your check fails is that this sshid command will probably count itself in the total because there is a process with the whole subshell command text in.

Also, there is no point in the awks. It just pulls one field out of one line, but you then just count the lines anyway. Must be the same number.

Your test also allows double the number of sessions - half through local login and half through remote ssh, because the tests are separate.

Finally, there is not much point in counting login sessions. Anybody can use their first session to start up as many new windows as they like, with xterm &.

If you can explain what problem you are actually trying to solve, we might be able to see a better way to achieve it. Personally, I would start with a root cron job that counts tty sessions by user, and flashes up a window asking them to cut back, and also emails sysadmin so they can make the phone call when needed.

Hi Paul
Thanks a lot for your answer , also thank you Jalal , yes
I write some code on /etc/profile , the thing that I hadn't think about it was removing the /home/user/.bash_profile.so, i wrote these codes on /etc/profile

In the real , I don't want user (bsi) login more than max number , and also noone can't login with this user with su command mare than max number , for some security reason. I want to check the number of sessions opened by this user(with ssh,or directly login)

You can write a script to use lock files and message the user if a lock file
exists, but then if the user gets interrupted before the lock file is
removed, someone may have to clear the lock file. Putting process id and
user in the lock may minimize that so the users login will be able to clear
the lock if the user is not active.

One other thing you may want to consider is a block_message file that
prevents logins other than root and can tell them why and for how long they
can expect login to be disabled. This can be extremely useful when trying
to gain control over a system to allow root to perform maintenance in a less
disruptive way. If the block_message file exists, a message is displayed
and logins other than root are prevented. For root only, the login gets
the message and requires a keystroke to continue.

There is another way by using the script command ....by which you can perform the records of all the session.......whenever user'll login then execute a script command ....with -a option followed by filename...and you'll find the records in the filename which you've given.....