Anthony Akens wrote: > > From: John W. Krahn [mailto:[EMAIL PROTECTED]] > > > > "John W. Krahn" wrote: > > > > > > #!/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; > > > } > > > > Sorry, there could be multiple pids, so it should be: > > > > for my $user ( map [ (split)[0,1,4] ], grep m|\bpts/|, `w -l` ) { > > # print RES "$user->[1]\n"; > > my @pids = grep s/\D+//g&&/\d/, `ps -t $user->[1] -o pid`; > > print RES "$user->[0]\n"; > > print RES "killing process id @pids on $user->[1] because minutes "; > > print RES $user->[2] =~ /:/ ? 'greater than 60' : 'equal', " $user->[2]\n"; > > kill 9, @pids; > > } > > This solution seems to kill anything, here's a snippet of the log. > As you can see, it's hitting things low idle times. (I of course > commented out the kill line) > > mmorgan > killing process id PID > 80350 > on pts/0 because minutes equal 1 > CLanko > killing process id PID > 109034 > on pts/1 because minutes equal 0 > lestas > killing process id PID > 17490 > 23800 > 51560 > on pts/2 because minutes equal 36 > ruthw > killing process id PID > 24992 > 26024 > 30064 > on pts/3 because minutes equal 17 > annap > killing process id PID > 28626 > 34956 > 51884 > on pts/4 because minutes greater than 60 1:35 > annap > killing process id PID > 22890 > 40942 > 115930 > on pts/5 because minutes equal 7
Sorry about that. This tests for idle time greater than 40 seconds. #!/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"; next unless $user->[2] =~ /:/ or $user->[2] > 0.40; my @pids = grep s/\D+//g&&/\d/, `ps -t $user->[1] -o pid`; print RES "$user->[0]\n"; print RES "killing process id @pids on $user->[1] because minutes "; print RES $user->[2] =~ /:/ ? 'greater than 60' : 'equal', " $user->[2]\n"; kill 9, @pids; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]