artgenos has asked for the wisdom of the Perl Monks concerning the following question:

before it starts, yes i am a noob. minor perl skills, i hack out code as i need it and always small scripts.

but what i am doing here today is looking for a little bit of wisdom.

i have a linux box, centos6, that has two interfaces. i only bring one up at a time depending on the enviroment i am in. while writting a script to bring up an interface and the services that i want to run with that interface i noticed one problem, what happens when i bring them both up by accident?

network issues for starters. anyone know a bit of script that will check the status of the interface and return it?

Replies are listed 'Best First'.
Re: Status of all interfaces
by JavaFan (Canon) on Oct 25, 2011 at 00:38 UTC
    How's this a Perl issue?

    Anyway, what happens when you bring up two interfaces depends on how you configure the interfaces, how you set up your routes, and how your network topology is.

    Note that having (at least) two interfaces is very common -- an ethernet port and a loopback interface and you already have two.

    As for a script that checks the status of the interface, why a script? What's wrong with ifconfig?

Re: Status of all interfaces
by williams554 (Sexton) on Oct 25, 2011 at 03:27 UTC

    Hello,
    On my system...

    #!/usr/bin/perl use strict; my @if_lines = `ifconfig`; foreach (@if_lines) { #you could remove interfaces with next if /^stf/; #this says if the line starts with stf, skip it. next unless (/up/i); #this says only print if the line has up (ign +ore case). print; }

    This would just show up interfaces.
    You get the idea. You could put the system command into an array.
    Then filter in or out what you want to see...
    You can play with this idea. (Good project for yourself.)
    Good luck, Rob

Re: Status of all interfaces
by pvaldes (Chaplain) on Oct 25, 2011 at 19:20 UTC

    based in the former, a little golf

    ifconfig|perl -nle'next unless (/up\s/i); print;'