User:Rkorgmaa: Difference between revisions
From ICO wiki
Jump to navigationJump to search
Created page with 'Kood on võetud Toomas Rohumetsa wikist. https://wiki.itcollege.ee/index.php/User:Trohumet Antud skript suudab ka teistele võrguliidestele aliaseid külge pookida. <source lan…' |
No edit summary |
||
Line 66: | Line 66: | ||
fi | fi | ||
</source> | |||
<source ="bash"> | |||
#!/bin/bash | |||
if [ "$1" = "" ]; then | |||
echo "$(basename $0) kasutajanimi@host" | |||
exit 1 | |||
fi | |||
echo "Lubame $(whoami)@$(hostname) võtmete abil autentimise hosti $@" | |||
if [ -f "$HOME/.ssh/id_dsa" ]; then | |||
echo "DSA on juba loodud, jätkame" | |||
else | |||
ssh-keygen -t dsa -N "" -f $HOME/.ssh/id_dsa | |||
fi | |||
cat $HOME/.ssh/id_dsa.pub | ssh $@ "mkdir -p .ssh && cat >> .ssh/authorized_keys2" | |||
</source> | </source> |
Revision as of 12:32, 31 May 2011
Kood on võetud Toomas Rohumetsa wikist. https://wiki.itcollege.ee/index.php/User:Trohumet
Antud skript suudab ka teistele võrguliidestele aliaseid külge pookida.
#!/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
if [ -z $2 ];
then
iface="eth0"
else
iface=$2
fi
#Kontroll kas IP on parameetrina antud
if [ $# -lt 1 ]; then
echo "Skripti kasutamine $(basename $0) <ip-address> <interface>(optional)"
exit 1
fi
IP=$1
#Aliaste kontroll
x=($(ifconfig | grep $iface: | 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 $iface:$nr
iface $iface:$nr inet static
address $IP
netmask $(ifconfig $iface | 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
#!/bin/bash
if [ "$1" = "" ]; then
echo "$(basename $0) kasutajanimi@host"
exit 1
fi
echo "Lubame $(whoami)@$(hostname) võtmete abil autentimise hosti $@"
if [ -f "$HOME/.ssh/id_dsa" ]; then
echo "DSA on juba loodud, jätkame"
else
ssh-keygen -t dsa -N "" -f $HOME/.ssh/id_dsa
fi
cat $HOME/.ssh/id_dsa.pub | ssh $@ "mkdir -p .ssh && cat >> .ssh/authorized_keys2"