Your first problem is that the format of ifconfig -a may be different on different platforms. For example:
[root]# uname -s
Linux
[root]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:C0:9F:XX:XX:XX
inet addr:64.x.x.x Bcast:64.x.x.x Mask:255.255.254.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:193891504 errors:0 dropped:0 overruns:0 frame:0
TX packets:153456331 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:1718775511 (1639.1 Mb) TX bytes:3265401055 (3114.1
+ Mb)
Interrupt:16 Base address:0xecc0 Memory:fe100000-fe120000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:56540745 errors:0 dropped:0 overruns:0 frame:0
TX packets:56540745 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2665326103 (2541.8 Mb) TX bytes:2665326103 (2541.8
+ Mb)
Anyway you need to find a good way to chunkify the data into records. Assuming you get it in a scalar split "\n\n" should probably do the trick. Then the first string in your chunk is the interface name and m/status:\s+(\S+)/ will give your status. That won't work on Linux.
for my $chunk (split "\n\n", $data) {
my ($if) = $chunk =~ m/^(\S+)/;
my ($status) = $chunk =~ m/status:\s*(\S+)/;
print "$if: $status\n";
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|