LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > catkin
User Name
Password

Notices


Rate this Entry

Bash scrippet to extract all eth* addresses from /etc/network/interfaces

Posted 12-02-2014 at 08:03 AM by catkin

I looked for such a script on the 'net and did not find so here's a solution, tessted with the edge case of an address line at the end of the file:
Code:
#!/bin/bash

eth_regex=^eth

true=true
false=

address=
have_iface_flag=$false
while read -r word1 word2 word3 word4 _
do
    case $word1 in  
         iface )
             [[ $word2 =~ $eth_regex && $word4 != dhcp ]] \
                 && have_iface_flag=$true
             ;;  
         address )
             if [[ $have_iface_flag ]]; then
                 eth_addresses+=($word2)
                 have_iface_flag=$false
             fi  
             ;;  
    esac
done < /etc/network/interfaces

[[ $have_iface_flag && $address != '' ]] && eth_addresses+=($address)

if [[ $eth_addresses != '' ]]; then
    for ((i=0;i<${#eth_addresses[*]};i++))
    do  
        echo "eth_addresses[$i]: ${eth_addresses[i]}"
    done
fi
Posted in Uncategorized
Views 1209 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 06:34 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration