Saturday, May 31, 2014

Parse network configuration data from network config file

Script

#!/usr/bin/perl
open (FILE, '/etc/sysconfig/network-scripts/ifcfg-eth0');


print "Parameter  $parameter";
print "                        Details  $details\n";
print "==========                         ========\n";

while (<FILE>)
{
chomp;
($parameter, $details) = split("=");
print "$parameter";
print "                         $details\n";
}

close (FILE);


Execution

xyz41.us.company.com: / >
xyz41.us.company.com: / >
xyz41.us.company.com: / > cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO=static
NM_CONTROLLED="no"
ONBOOT="yes"
TYPE="Ethernet"
UUID="ca8416d3-92ae-4052-a087-823b71798d58"
HWADDR=00:10:E0:42:19:33
IPADDR=10.149.117.241
PREFIX=23
GATEWAY=10.149.117.1
NETMASK=255.255.254.0
DNS1=129.77.231.27
DNS2=142.37.92.121
DNS3=197.116.81.157
DOMAIN=us.company.com
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
xyz41.us.company.com: / >
xyz41.us.company.com: / >
xyz41.us.company.com: / > ./parse-the-etc-sysconfig-network-scripts-ifcfg-eth0-file
Parameter                          Details
==========                         ========
DEVICE                         "eth0"
BOOTPROTO                         static
NM_CONTROLLED                         "no"
ONBOOT                         "yes"
TYPE                         "Ethernet"
UUID                         "ca8416d3-92ae-4052-a087-823b71798d58"
HWADDR                         00:10:E0:42:19:33
IPADDR                         10.149.117.241
PREFIX                         23
GATEWAY                         10.149.117.1
NETMASK                         255.255.254.0
DNS1                         129.77.231.27
DNS2                         142.37.92.121
DNS3                         197.116.81.157
DOMAIN                         us.company.com
DEFROUTE                         yes
IPV4_FAILURE_FATAL                         yes
IPV6INIT                         no
NAME                         "System eth0"
xyz41.us.company.com: / >
xyz41.us.company.com: / >
xyz41.us.company.com: / >

No comments:

Post a Comment