[geeks] hrm, possible?

David Cantrell geeks at sunhelp.org
Fri Jun 29 17:43:09 CDT 2001


On Fri, Jun 29, 2001 at 11:50:02AM -0500, Bill Bradford wrote:
> Given an output like this:
> 
> bash-2.02# ps -fe |grep ovw |grep display
>  mbarnes 20452     1  0 11:05:34 ?        0:09 /opt/OV/bin/ovw -rw -display 172.17.8.151:0
> dtrujill 20078     1  0 09:33:27 ?        0:17 /opt/OV/bin/ovw -ro -display 172.17.11.241:0
> lwilliam 20473     1  0 11:10:53 ?        0:10 /opt/OV/bin/ovw -ro -display 172.17.9.166:0
> ojanuari 20432     1  0 11:00:44 ?        0:10 /opt/OV/bin/ovw -ro -display 172.17.11.135:0
>  dher405 20049     1  0 09:29:07 ?        0:11 /opt/OV/bin/ovw/ -ro -display 172.17.11.136:0
>   jwells 20139     1  0 09:47:17 ?        0:19 /opt/OV/bin/ovw -ro -display 172.17.8.206:0
>  mbarnes 20029     1 45 09:28:10 ?       11:31 /opt/OV/bin/ovw -rw -display 172.17.8.151:0
>  kfuk855 20368     1  0 10:45:05 ?        0:08 /opt/OV/bin/ovw -rw -display 172.17.10.135:0
>   proman 20509     1  1 11:31:38 ?        0:09 /opt/OV/bin/ovw -ro -display 172.17.11.64:0
> 
> Anybody know if it would be possible to write a script (in whatever
> language necessary) that would detect the duplicate sessions (note
> processes 20432 and 20368, pointing to the same IP address)?

Completely untested, haven't even tried to compile it:

#!/usr/bin/perl5 -w

use strict;

my %users_by_ip();

foreach my $line (split(/\n/,`ps -fe |grep ovw |grep display`)) {
	$line=~/^\s*(\w+).*([\d\.]+):\d+/;
	my($user, $ip)=($1,$2);
	$users_by_ip{$ip}=[] unless(ref($users_by_ip{$ip}));
	push @{$users_by_ip{$ip}}, $user;
}

foreach my $ip (grep { @{$users_by_ip{$_}}>1 } keys %users_by_ip) {
	print "IP: $ip\n\t".join(', ', @{$users_by_ip{$ip}})."\n";
}

-- 
David Cantrell | david at cantrell.org.uk | http://www.cantrell.org.uk/david/

      Good advice is always certain to be ignored,
      but that's no reason not to give it            -- Agatha Christie



More information about the geeks mailing list