Anthony Akens wrote:
> 
> Hello,

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.

BTDT but on DG/UX not AIX.

> 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
> 
> 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


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

my $results = '/home/danb/killemresults';
open RES, '>>', $results or die "Cannot open $results: $!";
print "\n" . localtime() . "\nStarting\n";

for my $user ( map [ (split)[0,1,4] ], grep m|\bpts/|, `w -l` ) {
    # print RES "$user->[1]\n";
    my $pid = `ps -t $user->[1] -o pid`;
    print RES "$user->[0]\n";
    print RES "killing process id $pid on $user->[1] because minutes ";
    print RES $user->[2] =~ /:/ ? 'greater than 60' : 'equal', " $user->[2]\n";
    kill 9, $pid;
    }

__END__



John
-- 
use Perl;
program
fulfillment

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

Reply via email to