私は小さなファイルを持っています:
# Format
# <iface_name>,<ip_addr>,<ip_netmask>,<broadcast>,<eth_addr>,<status>,<obtaining_method>
eth0,192.168.0.11,255.255.255.0,192.168.0.255,4A:DD:00:00:05:00,up,static
lv0,172.20.8.12,255.255.248.0,172.20.15.255,4A:DD:00:FF:15:01,down,static
#lv0:0,172.20.16.12,255.255.248.0,172.20.23.255,4A:DD:00:FF:15:01,down,static
#lv0:1,172.20.24.12,255.255.248.0,172.20.31.255,4A:DD:00:FF:15:01,down,static
lv1,172.21.8.11,255.255.248.0,172.21.15.255,4A:DD:00:FF:15:02,down,dhcp
#lv1:0,172.21.16.1,255.255.248.0,172.21.23.255,4A:DD:00:FF:15:02,down,static
#lv1:1,172.21.24.1,255.255.248.0,172.21.31.255,4A:DD:00:FF:15:02,down,static
mv0,10.100.0.1,255.255.255.0,10.100.0.255,40:FD:00:00:01:0A,up,static
lp0,172.22.0.12,255.255.255.0,172.22.0.255,4A:DD:00:FF:15:04,down,static
lp1,172.22.1.12,255.255.255.0,172.22.1.255,4A:DD:00:FF:15:05,down,static
dummy0,192.168.111.100,255.255.255.0,192.168.111.255,00:00:00:00:00:00,down,static
1サイクルですべてのインターフェイスパラメータを取得するというアイデアがあり、次の式を作成しました。
#!/bin/sh
SPATH=/mnt/dcu/tmp/
for INTERFACE in $(awk -F\, '/^[^#]/ {print $1}' $SPATH/ifaces); do
INTERFACE_SETTINGS=$(awk -F\, '$1 ~ interface_name {print $2,$3,$4,$5,$6,$7}' interface_name=$INTERFACE $SPATH/ifaces)
set $INTERFACE_SETTINGS
IPADDR=$1
NETMASK=$2
BROADCAST=$3
MACADDR=$4
STATE=$5
METHOD=$6
sed -r -i -e "/$INTERFACE/s/^([^,]*,)([^,]*,)([^,]*,)([^,]*,)([^,]*,)([^,]*,)([^,]*)$/$INTERFACE,$IPADDR,$NETMASK,$BROADCAST,$MACADDR,$STATE,$METHOD/" /etc/network/ifaces
done
しかし、それは次のことを行います:
# Format
# <iface_name>,<ip_addr>,<ip_netmask>,<broadcast>,<eth_addr>,<status>,<obtaining_method>
eth0,192.168.0.11,255.255.255.0,192.168.0.255,4A:DD:00:00:05:00,up,static
lv0,172.20.8.12,255.255.248.0,172.20.15.255,4A:DD:00:FF:15:01,down,static
lv0,172.20.8.12,255.255.248.0,172.20.15.255,4A:DD:00:FF:15:01,down,static
lv0,172.20.8.12,255.255.248.0,172.20.15.255,4A:DD:00:FF:15:01,down,static
lv1,172.21.8.11,255.255.248.0,172.21.15.255,4A:DD:00:FF:15:02,down,dhcp
lv1,172.21.8.11,255.255.248.0,172.21.15.255,4A:DD:00:FF:15:02,down,dhcp
lv1,172.21.8.11,255.255.248.0,172.21.15.255,4A:DD:00:FF:15:02,down,dhcp
mv0,10.100.0.1,255.255.255.0,10.100.0.255,40:FD:00:00:01:0A,up,static
lp0,172.22.0.12,255.255.255.0,172.22.0.255,4A:DD:00:FF:15:04,down,static
lp1,172.22.1.12,255.255.255.0,172.22.1.255,4A:DD:00:FF:15:05,down,static
dummy0,192.168.111.100,255.255.255.0,192.168.111.255,00:00:00:00:00:00,down,static
コメントされたインターフェースの変更を取得します。
私はそれに対して例外を作ろうとしましたが、1行では機能しません:
awk -F\, '{ if ($1 !~ /[#]|^$/interface_name ) {print $2,$3,$4,$5,$6,$7} }' interface_name=lv0 /etc/network/ifaces
192.168.0.1 255.255.255.0 192.168.0.255 4A:DD:00:00:01:0A up static
172.20.8.1 255.255.248.0 172.20.15.255 4A:DD:00:FF:15:01 up static
172.21.8.1 255.255.248.0 172.21.15.255 4A:DD:00:FF:15:02 down static
10.10.0.1 255.255.255.0 10.10.0.255 40:FD:00:00:01:0A down static
172.22.0.1 255.255.255.0 172.22.0.255 4A:DD:00:FF:15:04 down static
172.22.1.1 255.255.255.0 172.22.1.255 4A:DD:00:FF:15:05 down static
192.168.111.111 255.255.255.0 192.168.111.255 00:00:00:00:00:00 down static
私の場合、どうすればそれを行うことができますか?
前もって感謝します。