我有一个有很多VLAN的Debian服务器。 所有的vlan从1开始。我需要从文件中读取所有IP,并将其输出到其他文件中。 一切都好,但我有一个增量variables的问题。
if [ -f /root/ip ]; then for IP_ADD in `grep -v ^# /root/ip`; do eth=1 eth=`expr $eth + 1` cat >> "/root/inter" <<END auto eth0:$eth iface eth0:$eth inet static address $IP_ADD netmask 255.255.255.0 END done fi
运行这个脚本后,我有文件“inter”输出:
auto eth0:2 iface eth0:2 inet static address 192.168.110.1 netmask 255.255.255.0 auto eth0:2 iface eth0:2 inet static address 192.168.109.1 netmask 255.255.255.0 auto eth0:2 iface eth0:2 inet static address 192.168.108.1 netmask 255.255.255.0 auto eth0:2 iface eth0:2 inet static address 192.168.107.1 netmask 255.255.255.0
我的variableseth递增,但只有一次。 我哪里有错误? 请帮忙。
在每次迭代中,您总是将variables重置为1。
把最初的
eth=1
跳出循环。
其他小问题:您不需要分叉进程来进行计算:
let "eth=$eth + 1"
是一个内部的bash。