[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: awk or sed?



On Wed, 22 Sep 1999, Steve Lamb wrote:

>     Short answer: awk
> 
>     Longer answer (by one letter): perl
> 
> 
> eth0      Link encap:Ethernet  HWaddr 00:20:78:10:4D:63  
>           inet addr:209.178.54.157  Bcast:209.178.54.255  Mask:255.255.255.0
>           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
>           RX packets:6210311 errors:0 dropped:0 overruns:0 frame:45
>           TX packets:5313311 errors:1 dropped:0 overruns:0 carrier:0
>           collisions:472 txqueuelen:100 
>           Interrupt:10 Base address:0x6400 
> 
>     If the above is the example...
> 
> while(<>){
>   if ($_ =~ /inet addr:(\n+)\.(\n+)\.(\n+)\.(\n+)/){
>     $ipaddr = "$1.$2.$3.$4";
>   }
>   $return = `nslookup $1.$2.$3.$4`;
>   print($return);
> }
> 
>     Of course, the if line could be reduced, but breaking out the octets
> allows you to do other manipulations on them as needed.

Thanks for all replies. It was actually cut I was thinking of initially.
I couldn't get this one to go, nothing was going into $1,$2, or $ipaddr. A
friend who knows perl wrote me another, like this:

$ifconfig = `/sbin/ifconfig eth0`;
($ip) = $ifconfig =~ /inet addr:(\S+)/;
print ">$ip<\n";
$host = `host $ip`;

($name) = $host =~ /^Name:\s+(.+)$/m;
print ">$name<\n";

($hostname) = $name =~ /^(.+?)\..*/;
print ">$hostname<\n";

`hostname $hostname`;

Thanks again,

Tim.

-- 
Tim Thomson               tim@tui.dhs.org             ICQ: 18073712




Reply to: