1846305 Members
3648 Online
110256 Solutions
New Discussion

Re: unix script

 
SOLVED
Go to solution
Mario Edgardo
Occasional Contributor

unix script

We have a system running in HP-UX 11i Operatyng system and we have restrictions in number of licenses.

We have 3 types of restrictions about the number of session allowed to each user.

Some user have permission to have 3 sessions open, some others 2 sessions open and some others only one session open.

We need to make a script or as the propose of Michael, we need to make a trap 1 in the users.profile, to kill the old session or hanging processes,when the users that has permission to have only one session open, try to open a second session, and this second session.

And in resume the old session has to be kill, when that kind of users open a new session, because only the new session must be working.

Please write that comands or script to make that????

Regards

Mario
5 REPLIES 5
Hoefnix
Honored Contributor

Re: unix script

You can find a solution in the responses of Elmar in the next forum question.

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=291677

Instead of doing an echo you can do a kill of the old sessions

Good luck with it.

Regards,

Peter
Mario Edgardo
Occasional Contributor

Re: unix script

In this moment I have the script in the user profile to make the restricition of the number of sessions allowed and that script is the next.

# Limita el número de sesiones en RCC
no_logins=`who|grep $LOGNAME|wc -l`
if [[ $no_logins -gt 3 ]]
then
echo "LO SIENTO, YA TIENES UNA SESION EN USO"
exit
fi

but if the user try to open a second session, the system, left hanging process, licence use, and for this reason we need to kill the old session when a user open a new session, this script will be only for users that have permission to have one session open.

Please give me script to make tha
Mario Edgardo
Occasional Contributor

Re: unix script

I think that is a good idea to use a trap 1 in the user.profile,please write the script to kill the old session when a user open a new session
Hoefnix
Honored Contributor
Solution

Re: unix script

I think next will work for users that are allowed 1 session.

mytty=`tty | sed 's/\/dev\///'`
no_logins=`who|grep $LOGNAME|wc -l`
if [[ $no_logins -gt 3 ]]
then
echo "LO SIENTO, YA TIENES UNA SESION EN USO"
echo"will now kill old sessions"
for p_id in `ps -u $LOGNAME | grep -v $mytty | grep -v PID | awk '{ print $1 }' i | sort -nr`
do
if [ `ps -p $p_id | wc -l` -eq 2 ]
then
kill $p_id
fi
done
exit
fi

Regards,

Peter

Hoefnix
Honored Contributor

Re: unix script

misstake in next line (cute and paste problem) sorry:

should be like this:
for p_id in `ps -u $LOGNAME | grep -v $mytty | grep -v PID | awk '{ print $1 }' | sort -nr`

Replace line with above line.

Regards,

Peter