LINUX.ORG.RU
решено ФорумAdmin

[bash]bash for loop или for i in

 


0

1

Предположим имеется четыре интерфейса

4: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether c2:e1:27:eb:ea:ba brd ff:ff:ff:ff:ff:ff
5: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 52:d0:93:b0:64:fd brd ff:ff:ff:ff:ff:ff
6: eth3: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 7e:a5:81:b6:6a:ef brd ff:ff:ff:ff:ff:ff
7: eth4: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether c6:37:27:2b:24:35 brd ff:ff:ff:ff:ff:ff

Как поднять линк понятно

bridge:~# for i in {1..4}; do ip l s eth${i} up; done

А вот как назначить vlan'ы из диапозона 192.168.{vlanid}.254 запутался

9: vlan2@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue 
    link/ether 42:1a:31:29:87:e6 brd ff:ff:ff:ff:ff:ff
10: vlan3@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue 
    link/ether 42:1a:31:29:87:e6 brd ff:ff:ff:ff:ff:ff
11: vlan4@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue 
    link/ether 42:1a:31:29:87:e6 brd ff:ff:ff:ff:ff:ff
12: vlan5@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue 
    link/ether 42:1a:31:29:87:e6 brd ff:ff:ff:ff:ff:ff

Получается две переменные, так не прокатит

for i in {2..5}; do ip a a 192.168.${i}.254/24 dev vlan{i}; done
Ответ на: комментарий от AITap
bridge:~# for i in {1..4}; do for j in {2..5}; do ip a a 192.168.${i}/24 dev vlan${j}; done; done
bridge:~# ip -4 a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue 
    inet 127.0.0.1/8 scope host lo
9: vlan2@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue 
    inet 192.168.1.0/24 scope global vlan2
    inet 192.168.2.0/24 scope global vlan2
    inet 192.168.3.0/24 scope global vlan2
    inet 192.168.4.0/24 scope global vlan2
10: vlan3@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue 
    inet 192.168.1.0/24 scope global vlan3
    inet 192.168.2.0/24 scope global vlan3
    inet 192.168.3.0/24 scope global vlan3
    inet 192.168.4.0/24 scope global vlan3
11: vlan4@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue 
    inet 192.168.1.0/24 scope global vlan4
    inet 192.168.2.0/24 scope global vlan4
    inet 192.168.3.0/24 scope global vlan4
    inet 192.168.4.0/24 scope global vlan4
12: vlan5@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue 
    inet 192.168.1.0/24 scope global vlan5
    inet 192.168.2.0/24 scope global vlan5
    inet 192.168.3.0/24 scope global vlan5
    inet 192.168.4.0/24 scope global vlan5

А надо, чтобы вот так

bridge:~# for i in {2..5}; do ip a a 192.168.${i}.254/24 dev vlan${i}; done
bridge:~# ip -4 a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue 
    inet 127.0.0.1/8 scope host lo
9: vlan2@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue 
    inet 192.168.2.254/24 scope global vlan2
10: vlan3@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue 
    inet 192.168.3.254/24 scope global vlan3
11: vlan4@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue 
    inet 192.168.4.254/24 scope global vlan4
12: vlan5@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue 
    inet 192.168.5.254/24 scope global vlan5
anton_jugatsu ★★★★
() автор топика
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.