User:Trohumet: Difference between revisions
From ICO wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
#Autor: Toomas Rohumets A21 | #Autor: Toomas Rohumets A21 | ||
#Skript, mis loob Ubuntu serverile IP aliase | #Skript, mis loob Ubuntu serverile IP aliase | ||
#Versioon 0. | #Versioon 0.5 | ||
#Õiguste kontroll | #Õiguste kontroll | ||
Line 21: | Line 21: | ||
IP=$1 | IP=$1 | ||
#Aliaste kontroll | |||
x=($(ifconfig | grep eth0: | cut -d":" -f2 | cut -d" " -f1)) | |||
if [ ! -n "$x" ]; then | |||
nr=0 | |||
else | |||
nr=${#x[@]} | |||
fi | |||
#Ping, kontrollimaks kas IP on kasutuses | #Ping, kontrollimaks kas IP on kasutuses | ||
ping -c 3 $IP | ping -c 3 $IP | ||
Line 32: | Line 41: | ||
#IP ja võrgumaski sisestus /etc/network/interfaces faili | #IP ja võrgumaski sisestus /etc/network/interfaces faili | ||
cat >> /etc/network/interfaces <<EOF | cat >> /etc/network/interfaces <<EOF | ||
auto eth0: | auto eth0:$nr | ||
iface eth0: | iface eth0:$nr inet static | ||
address $IP | address $IP | ||
netmask $(ifconfig eth0 | grep Mask | cut -d ':' -f 4) | netmask $(ifconfig eth0 | grep Mask | cut -d ':' -f 4) |
Revision as of 07:37, 17 May 2011
Quest14
<source lang="bash">
- !/bin/bash
- Autor: Toomas Rohumets A21
- Skript, mis loob Ubuntu serverile IP aliase
- Versioon 0.5
- Õiguste kontroll
if [ $UID -ne 0 ]; then echo "Käivita skript $(basename $0) juurkasutaja õigustega" exit 1
fi
- Kontroll kas IP on parameetrina antud
if [ $# -ne 1 ]; then
echo "Käivita skript $(basename $0) koos IPga" exit 1
fi
IP=$1
- Aliaste kontroll
x=($(ifconfig | grep eth0: | cut -d":" -f2 | cut -d" " -f1))
if [ ! -n "$x" ]; then nr=0 else nr=${#x[@]} fi
- Ping, kontrollimaks kas IP on kasutuses
ping -c 3 $IP
if [ $? -eq 0 ]; then
echo "IP on olemas" exit 1
else
echo "IP on vaba"
- IP ja võrgumaski sisestus /etc/network/interfaces faili
cat >> /etc/network/interfaces <<EOF
auto eth0:$nr iface eth0:$nr inet static
address $IP netmask $(ifconfig eth0 | grep Mask | cut -d ':' -f 4)
EOF
- Võrgule restart
/etc/init.d/networking stop /etc/init.d/networking start
- Tulemus
echo "Loodi alias IPga $IP" fi