1752762 Members
4810 Online
108789 Solutions
New Discussion юеВ

Purge Redundant logons

 
poundpooch
Advisor

Purge Redundant logons

Hi
I've been having an issue where there are a number of redundant sh connections left hanging on my system for a few days.This is a result of people incorrectly exiting the system.My cpu can reach 100% as a result.Is there a way of automatically purging redundant logons at the end of the day in Hp-Ux?
4 REPLIES 4
Pete Randall
Outstanding Contributor

Re: Purge Redundant logons

The difficulty comes from determining who should still be logged in and who should not. I use a script like this:

ps -ef |grep -v daemon |grep -v PID |grep -v bAcKuP4N |grep -v ops |grep -v root |grep -v informix |grep -v lp
echo "****************************************************************"
echo "TO TOTALLY REMOVE THESE USERS "
echo " HIT ENTER, CTRL-C TO ABORT. "
echo "****************************************************************"
read nothing
ps -ef |grep -v daemon |grep -v PID |grep -v bAcKuP4N |grep -v ops |grep -v root |grep -v informix |grep -v lp | awk '{ print $2 }' > /tmp/killlist
for i in `cat /tmp/killlist`
do
kill $i
kill -9 $i
done


Pete

Pete
poundpooch
Advisor

Re: Purge Redundant logons

Thats excellent thanks Pete it works for my users,but is there anyway of filtering this through group membership.We have a group of users in IT as they are programmers I don't need to kill their logons
Pete Randall
Outstanding Contributor

Re: Purge Redundant logons

I guess you could look up each user in /etc/passwd to determine their primary group, then filter on that. I just extend my grep list to exclude the programmers logons.


Pete

Pete
Dennis Handly
Acclaimed Contributor

Re: Purge Redundant logons

>Pete: I guess you could look up each user in /etc/passwd to determine their primary group,

You can do that by: $ id -gn name

ps -ef | fgrep -v PID | while read user pid dummy ; do
if [ $(id -ng $user) != "goodgrp" ]; then
echo $pid
fi
done

You can also optimize the greps by:
ps -ef |grep -v -e daemon -e PID -e bAcKuP4N -e ops -e root -e informix -e lp

You can also put these in a file:
ps -ef | grep -v -f good-guys