Operating System - HP-UX
1833019 Members
2152 Online
110048 Solutions
New Discussion

script wanted about user login

 
SOLVED
Go to solution
peterchu
Super Advisor

script wanted about user login

I want to control the no. of user login , the max. of login is limited to 300 , but it always over 300 logins at the peak hour , so I want to kill five users who are idle for most long time because I want to remain the no. of login to 295 , can suggest how to write the shell script ? thx.
3 REPLIES 3
Michael Tully
Honored Contributor
Solution

Re: script wanted about user login

If they have shell access, you can add the shell variable 'TMOUT' to each one. The sh-posix man page has details.

You could as an alternative use another method, and that is add some lines of code to the /etc/profile file, where it evaluates the number of users logged in, and if there are 300 already, it will log them out.

This post should help
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=534189
Anyone for a Mutiny ?
peterchu
Super Advisor

Re: script wanted about user login

thx Michael's reply,

I find the script that u provide , it will kill the idle process that idle over a certain time , but I want a script that is more intelligence , it can kill the logins their idle time are the most long in the system , do anyone have such script ? thx.
Muthukumar_5
Honored Contributor

Re: script wanted about user login

hai,

We can get the idle time of users with who -u or w command.

#!/usr/bin/ksh
# user login control

max=300

while true; do

cnt=`who -R | wc -l`
kill_cnt=$(($cnt-$max+5))
loop=0

while [[ $loop -lt $kill_cnt ]]; do

# send the mail to ip-address
echo "you are being idle" > mail `who -Ru | sort -k 6 | tail -1 | awk '{ print $8 }'`

# kill them
kill -9 `who -Ru | sort -k 6 | tail -1 | awk '{ print $7 }'`
let loop=loop+1
done

# Sleep for some time to synchronize
sleep 120

done

It will check and kill the exceeding users

Regards,
Muthukumar.


Easy to suggest when don't know about the problem!