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.4 | ||
#Õiguste kontroll | #Õiguste kontroll | ||
if [ $UID -ne 0 ]; then | if [ $UID -ne 0 ]; then | ||
echo "Käivita skript $(basename $0) juurkasutaja õigustega" | echo "Käivita skript $(basename $0) juurkasutaja õigustega" | ||
exit 1 | exit 1 | ||
fi | fi | ||
#Kontroll kas IP on parameetrina antud | #Kontroll kas IP on parameetrina antud | ||
if [ $# -ne 1 ]; then | if [ $# -ne 1 ]; then | ||
Line 19: | Line 19: | ||
exit 1 | exit 1 | ||
fi | fi | ||
IP=$1 | IP=$1 | ||
#Ping, kontrollimaks kas IP on kasutuses | #Ping, kontrollimaks kas IP on kasutuses | ||
ping -c 3 $IP | ping -c 3 $IP | ||
if [ $? -eq 0 ]; then | if [ $? -eq 0 ]; then | ||
echo "IP on olemas" | echo "IP on olemas" | ||
Line 30: | Line 30: | ||
else | else | ||
echo "IP on vaba" | echo "IP on vaba" | ||
#IP 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:0 | auto eth0:0 | ||
iface eth0:0 inet static | iface eth0:0 inet static | ||
address $IP | address $IP | ||
netmask | netmask $(ifconfig eth0 | grep Mask | cut -d ':' -f 4) | ||
EOF | EOF | ||
#Võrgule restart | #Võrgule restart | ||
/etc/init.d/networking | /etc/init.d/networking stop | ||
/etc/init.d/networking start | |||
#Tulemus | #Tulemus | ||
echo "Loodi alias IPga $IP" | echo "Loodi alias IPga $IP" | ||
fi | fi |
Revision as of 16:19, 11 May 2011
Quest14
<source lang="bash">
- !/bin/bash
- Autor: Toomas Rohumets A21
- Skript, mis loob Ubuntu serverile IP aliase
- Versioon 0.4
- Õ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
- 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:0 iface eth0:0 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