Here is a Perl script which show the IP to every process
Posted: Sat Apr 24, 2004 9:01 am
Hello,
i've wrote a perl script, which shows the ps ax output with one further field: the ip address. It is much slower then the ps command, but I don't mind.
have fun!
Markus
i've wrote a perl script, which shows the ps ax output with one further field: the ip address. It is much slower then the ps command, but I don't mind.
- Code: Select all
#!/usr/bin/perl
$a = `ps ax`;
@r = split(/\n/, $a);
$co=0;
foreach $_(@r) {
$co++;
/^([0-9]+)\s/;
$c = `cat /proc/$1/ipaddr 2>/dev/null`;
chomp($c);
if ($co==1) {
printf ("%-15s ", " IP");
} else {
if ( $c != "") {
printf ("%15s ",$c);
} else {
printf ("%15s ","-");
}
}
print;
print "\n";
}
have fun!
Markus