#!/bin/sh
#
# ifconfig-parse.sh - parse output from ifconfig and print
# in format suitable for eval in shell
#
# Developed by Lubommir Host 'rajo' <rajo AT platon.sk>
# Copyright (c) 2003 Platon SDG
# Licensed under terms of GNU General Public License.
# All rights reserved.
#
# $Platon$
# Parse output from ifconfig:
/sbin/ifconfig | \
awk 'BEGIN { interfaces=""; }
/^[a-zA-Z0-9]+/ {
iface=$1;
interfaces = sprintf("%s %s", interfaces, iface);
printf "\nIFACE_%s=\"%s\";\nHWaddr_%s=\"%s\";\nexport IFACE_%s HWaddr_%s\n",
$1, $1, $1, $5, $1, $1;
}
/^[ \t]+inet/ {
split($0, fields, "[ \t:]+");
printf "IP_%s=\"%s\";\nBcast_%s=\"%s\";\nMask_%s=\"%s\";\n",
iface, fields[4], iface, fields[6], iface, fields[8];
printf "export IP_%s Bcast_%s Mask_%s\n",
iface, iface, iface;
}
END { printf "\ninterfaces=\"%s\"\n", interfaces; }
'
Platon Group <platon@platon.org> http://platon.org/
|