in reply to Re: Back in the saddle...
in thread Back in the saddle...

A slightly revised, but still broken script:

#!/usr/local/bin/perl -w use strict; my $ifconfig = `/usr/etc/ifconfig ec0`; print "$ifconfig\n"; $_ = $ifconfig; my ($junk, $ip_address) = /^(.*\n.*inet\w)(\d{1,3}\.\d{1,3}\.\d{1,3 +})/; print "$junk $ip_address\n";

Running this results in the following:
ROOT 164 tech_support_4 //devel# ./net_config.test
ec0: flags=410c43<UP,BROADCAST,RUNNING,FILTMULTI, MULTICAST,LINK0,IPALIAS>
inet 172.22.43.157 netmask 0xfffffc00 broadcast 172.22.43.255
Use of uninitialized value at ./net_config.test line 11.
Use of uninitialized value at ./net_config.test line 11.

(That ifconfig output is only on two lines on the system.)

Replies are listed 'Best First'.
Re: Re: Re: Back in the saddle...
by graff (Chancellor) on Apr 05, 2003 at 01:29 UTC
    If this is the return when you run ifconfig:
    ec0: flags=410c43<UP,BROADCAST,RUNNING,FILTMULTI,MULTICAST,LINK0,IPALI +AS> inet 172.22.43.157 netmask 0xfffffc00 broadcast 172.22.43.255
    and this is your regex:
    /^(.*\n.*inet\w)(\d{1,3}\.\d{1,3}\.\d{1,3})/
    The problem is that you're trying to match and capture everything in the string up to and including the first IP address, when you don't need to. It's failing because of the part inet\w -- you're looking for an alphanumeric character immediately after the "t" of "inet", and there isn't one. The following would do what you want:
    my ($ip_address) = ( /inet\s+(\d{1,3}\.\d{1,3}\.d{1,3})/ );
    That is, match and capture the first three components of the IP address that follows one or more whitespace characters immediately after the first occurrence of "inet".