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);
vmnet1,lo,wlan0,vmnet8,eth0
: : much handwaving here my @results=grep /eth1/,`netstat -i`; : : I didn't test that, but should work... :
: : 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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |