0

I have a Debian server with many VLANs. All of that vlan started from 1. I need to read from file all IP, and output all of this in other file. All ok, but i have a problem with increment variable.

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

After run this script, i have in file "inter" output:

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

My variable eth is incremented, but only one time. Where i have error ? Please help.

1 Answers1

1

You always reset the variable back to 1 in every iteration.

Put the initial

eth=1

out of the loop.


Minor other concern: You don't need to fork a process to do the calculation:

let "eth=$eth + 1"

is a bash internal.

Sven
  • 97,248
  • 13
  • 177
  • 225