Tiny Core Linux
General TC => Programming & Scripting - Unofficial => Topic started by: krlosg7 on November 06, 2015, 04:51:56 AM
-
Hi all,
I have write a small script that allows every tinyvcore to start up with an IP static. To have this IP address the script must read mac address machine after boot.
the script is in /opt/script.sh and in my /opt/bootlocal.sh, I have this entry: /opt/script.sh &
Here is the script.
#!/bin/sh
pkill udhcpc
case 'cat /sys/class/net/eth0/address' in
52:54:00:12:34:56) IP='ifconfig eth0 192.168.1.1 netmask 255.255.255.0 up' ;;
52:54:00:12:34:57) IP='ifconfig eth0 192.168.1.2 netmask 255.255.255.0 up' ;;
52:54:00:12:34:58) IP='ifconfig eth0 192.168.1.3 netmask 255.255.255.0 up' ;;
52:54:00:12:34:59) IP='ifconfig eth0 192.168.1.4 netmask 255.255.255.0 up' ;;
*) IP='ifconfig eth0 192.168.1.5 netmask 255.255.255.0 up' ;;
esac
$IP
I reboot the machines. always every machine take the last IP.... how i can to fix it?
Any recommendation very welcome, Thanks in advance
-
You're using single quotes. That doesn't work as it's handled as a string. Use backticks instead.
Change this
case 'cat /sys/class/net/eth0/address' in
to this
case `cat /sys/class/net/eth0/address` in
or
case $(cat /sys/class/net/eth0/address) in
so it's interpreted as a command.
-
Why don't you just use dhcp and make the assignments in your dhcp server/router?
-
Hi krlosg7
You might also want to consider simplifying that code snippet to something like:
#!/bin/sh
pkill udhcpc
case `cat /sys/class/net/eth0/address` in
52:54:00:12:34:56) SUBNET=1 ;;
52:54:00:12:34:57) SUBNET=2 ;;
52:54:00:12:34:58) SUBNET=3 ;;
52:54:00:12:34:59) SUBNET=4 ;;
*) SUBNET=5 ;;
esac
ifconfig eth0 192.168.1.$SUBNET netmask 255.255.255.0 upNow the case statement is less busy and the intent is easier to follow.
-
the answer by Misalf and Rich work ;D.
gerald_clark talk about dhcp server but i have tried and that not work.
this is my topology.
multiple tap interface...
tap1: 10.10.10.1 /24
--------------------\ \
\------------\-------qemu server-----------ISC DHCP server
/ 10.10.10.252/ 10.10.10.253 10.10.10.254
--------------------/ OVS / eth1 eth1
tap2: 10.10.10.2 /24
I've been trying to get dhcp address by an ISC Server. I have one DHCP Server and one qemu server with multiple image tiny core.
Over the qemu server OVS switch connects tap interfaces.
Any help would be appreciated with dhcp server/router idea of gerald_clark. Thanks.
-
Make sure you use a bridged connection in your virtual machine setup.