So you noticed I didn't test in nearly enough :)

try adding a -w to the grep for 'word grepping' (add it in both places),
checking out the man page for grep may help.

It was a fast hack job, it may be better to get a process list of the
first, before the if statements, but I will leave that up to you to decide
:)

Also the whole 'process getting and killing' could be put in a procedure
accepting the user name and the message string ...but again you can decide
on that.

Glad you understood it, my first real hack at posting in here.

-----------------------------------------
Craig Moynes
[EMAIL PROTECTED]



                                                                                       
                                 
                      "Akens, Anthony"                                                 
                                 
                      <[EMAIL PROTECTED]>         To:       "Akens, Anthony" 
<[EMAIL PROTECTED]>, <[EMAIL PROTECTED]>        
                                               cc:       Craig 
Moynes/Markham/IBM@IBMCA                                 
                      06/11/02 03:23 PM        Subject:  RE: Killing Idle Users        
                                 
                      Please respond to                                                
                                 
                      "Akens, Anthony"                                                 
                                 
                                                                                       
                                 
                                                                                       
                                 



Found another problem...

The line
     my @inputP = qx!ps -e |grep $port!;
is matching a bit overzealously...  For instance,
if $port = pts/6 it matches (and therefore would kill)
not only processes on port pts/6, but also pts/61, pts/62
etc.

Is there a better way to limit that?

Tony Akens
[EMAIL PROTECTED]

-----Original Message-----
From: Akens, Anthony
Sent: Tuesday, June 11, 2002 1:49 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: RE: Killing Idle Users


Thanks!
The only thing I saw to change was the line

if ( $idle =~ /^\d+$/ && $idle > 0 )

to

if ( $idle =~ /^\d+$/ && $idle > $USER_IDLE )

I'm going to do some testing to be safe, but will probably
put this in place soon - and the great part is that I
understand *most* of it!

Tony Akens
[EMAIL PROTECTED]


-----Original Message-----
From: Craig Moynes/Markham/IBM [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 11, 2002 1:00 PM
To: Akens, Anthony
Cc: [EMAIL PROTECTED]
Subject: RE: Killing Idle Users


Something like this perhaps ?:

#!/usr/bin/perl -w
use strict;

my $USER_IDLE = 40;

my @input = qx!w -l!;
shift @input;
shift @input;

foreach my $entry ( @input )
{
        my ($user, $port, undef, $idle) = split('\s+', $entry);

        if ( $idle =~ /^\d+$/ && $idle > 0 )
        {
                # Kill all the users processes
                my @inputP = qx!ps -e |grep $port!;
                foreach my $entryP ( @inputP )
                {
                        my ($pid) = (split('\s+', $entryP))[1];
                        print "killing process $pid. ".
                                "user $user idle for $idle.\n";
                        #qx!kill -9 $pid!;
                }
        }
        elsif ( $idle =~ /:/ )
        {
                # Kill all the users processes
                my @inputP = qx!ps -e |grep $port!;
                foreach my $entryP ( @inputP )
                {
                        my ($pid) = (split('\s+', $entryP))[1];
                        print "killing process $pid ".
                                "idle for $idle.\n";
                        #qx!kill -9 $pid!;
                }
        }

}


-----------------------------------------
Craig Moynes
[EMAIL PROTECTED]



                      "Akens, Anthony"

                      <[EMAIL PROTECTED]>         To:
<[EMAIL PROTECTED]>

                                               cc:

                      06/11/02 01:13 PM        Subject:  RE: Killing Idle
Users
                      Please respond to

                      "Akens, Anthony"






Here's the shell script, for those interested.  Sorry for the
lack of comments, but it's not to hard to figure out with a
little patience...

-----------
PTS=`w -l | grep pts | cut -c10-15`
echo "" >> /home/danb/killemresults
RIGHTNOWDATE=`date`
echo $RIGHTNOWDATE >> /home/danb/killemresults
echo "Starting" >> /home/danb/killemresults
for i in $PTS
do
             #echo $i >> /home/danb/killemresults
        MINUTES=`w -l | grep -w $i | cut -c38-39`
             for j in $MINUTES
             do
                         if (($j > 40))
                         then
                             PID=`ps -e | grep -w $i' ' | cut -c2-6`
                    USERNAME=`w -l | grep -w $i`
                    echo $USERNAME >> /home/danb/killemresults
                             echo 'killing process id ' $PID ' on ' $i '
because minutes equal ' $MINUTES >> /home/danb/killemresults
                         kill -9 $PID
                         fi
             done
             MINUTES=`w -l | grep -w $i | cut -c37`
             for j in $MINUTES
             do
                         if [ "$j" = ":" ]
                         then
                             PID=`ps -e | grep -w $i' ' | cut -c2-6`
                    USERNAME=`w -l | grep -w $i`
                    echo $USERNAME >> /home/danb/killemresults
                             echo 'killing process id ' $PID ' on ' $i '
because minutes greater than 60 ' $MINUTES >> /home/danb/killemresults
                            kill -9 $PID
                         fi
             done
done

-------------

-----Original Message-----
From: [EMAIL PROTECTED]
Sent: Tuesday, June 11, 2002 12:15 PM
To: Akens, Anthony; [EMAIL PROTECTED]
Subject: RE: Killing Idle Users


I am not in a position to offer advice but would love to see it .




-----Original Message-----
From: Akens, Anthony [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 11, 2002 10:48 AM
To: [EMAIL PROTECTED]
Subject: Killing Idle Users


Hello,
I'm a sys-admin on an AIX (4.3) machine, and I'm trying to work
with a vendor program that doesn't behave very nicely.  Basically,
if a user's connection to the server is inappropriately severed
the application keeps right on chugging, leaving the user
logged in.  By inappropriately severed I mean if our link to the
site the user is at goes down, which happens more often then
I'd like, but that's a different problem.

Anyway, back to the question...
There are quite a few problems with these unconnected sessions
being stuck out there, not least of which is that they eat up a
user license, which are pretty limited in amount.  One good power
outage or link failure at can make it so we're out of licenses.
In that event the vendor says "Kill them by hand, do NOT automate
the process" which is all fine and good except that we have
several hundred users.  That's a lot of time.

The first thought was to use a shell idle logout time, but the
program doesn't respond to the request and remains logged in.

The previous administrator had made a shell script to check idle
times and automatically log out the users, however since I've
taken over the box the uptimes have been far greater (I don't
believe in the same "reboot often" premise that he did) and now
his script has shown a severe weakness: It's not written to
handle longer PIDs.

Rather then trying to fix his shell script, which is rather
convoluted, I thought it would be a perfect candidate for perl,
which I am just learning.  If I post the script, can I get some
pointers on re-writing it?  Thanks for your time

Tony Akens
[EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to