User:Trohumet

From ICO wiki
Revision as of 07:37, 17 May 2011 by Trohumet (talk | contribs)
Jump to navigationJump to search

Quest14

<source lang="bash">

  1. !/bin/bash
  2. Autor: Toomas Rohumets A21
  3. Skript, mis loob Ubuntu serverile IP aliase
  4. Versioon 0.5
  1. Õiguste kontroll

if [ $UID -ne 0 ]; then echo "Käivita skript $(basename $0) juurkasutaja õigustega" exit 1

fi

  1. Kontroll kas IP on parameetrina antud

if [ $# -ne 1 ]; then

       echo "Käivita skript $(basename $0) koos IPga"
       exit 1

fi

IP=$1

  1. Aliaste kontroll

x=($(ifconfig | grep eth0: | cut -d":" -f2 | cut -d" " -f1))

if [ ! -n "$x" ]; then nr=0 else nr=${#x[@]} fi

  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"
  1. 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

  1. Võrgule restart

/etc/init.d/networking stop /etc/init.d/networking start

  1. Tulemus

echo "Loodi alias IPga $IP" fi