You didn't specify what OS you are on, but it looks like you are running on Linux given you are looking for "eth?".

Here is a sniglet that I pulled out of an RC script of mine running on RH 9.0 and therefore tested on RH 9.0. There is enough common stuff here that it should run on any flavor of *nix and revolves around the netstat -i command invokation.

#!/usr/bin/perl -w ################################ use strict; open(PIPE,'netstat -i|') or die $!; my $header=<PIPE>; # Kernel Interface Table $header=<PIPE>; # The real header chomp $header; # # Oh... what the hey... Let's parse it just for grins. my @fields=split(/[\s]+/,$header); my %ifTable=(); # Set up an empty assoc array while (my $line=<PIPE>){ chomp $line; my @f=split(/[\s]+/,$line); foreach my $ix(1..$#f){ $ifTable{$f[0]}->{$fields[$ix]}=$f[$ix]; } } # # But wait... you just wanted the IF names: printf "%s\n",join(",",keys %ifTable);

when I ran it on my laptop (another flavor of Linux other than where it usually runs) it not only worked portably but I got the following:
vmnet1,lo,wlan0,vmnet8,eth0

Now, this lists the interfaces, if you wanted to just determine the existance of an interface you could also do something like:
: : much handwaving here my @results=grep /eth1/,`netstat -i`; : : I didn't test that, but should work... :

Using my much wordier code you could (instead of printing) also do:
: : print "It's there\n" if $ifTable{'eth1'}; # or whatever : :

Hope this is of some small use to you...


In reply to Re: How can I check if the eth? exist by blue_cowdawg
in thread How can I check if the eth? exist by A_Banknote

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.