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 |
||
(3 intermediate revisions by the same user not shown) | |||
Line 66: | Line 66: | ||
fi | fi | ||
</source> | |||
Luua skript, mis seadistab võtmete baasil autentimise ssh abil. | |||
<source lang="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> | |||
Tegin pythoni skripti, mis leiab etteantud kataloogist kõik katkised nimelingid | |||
<source lang="Python"> | |||
#!/usr/bin/python | |||
# -*- coding: utf-8 -*- | |||
#Autor: Rain Kõrgmaa | |||
#Ver: 0.11a | |||
import os | |||
import sys | |||
if(len(sys.argv) != 2): | |||
print "Kasutamine: %s <kaust>" % sys.argv[0] | |||
exit(255) | |||
path=sys.argv[1] | |||
dir=os.listdir(path) | |||
for fname in dir: | |||
if (os.path.exists(fname) == False) and (os.path.islink(fname) == True): | |||
print path+fname | |||
</source> | </source> |
Latest revision as of 21:43, 1 June 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
Luua skript, mis seadistab võtmete baasil autentimise ssh abil.
#!/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"
Tegin pythoni skripti, mis leiab etteantud kataloogist kõik katkised nimelingid
#!/usr/bin/python
# -*- coding: utf-8 -*-
#Autor: Rain Kõrgmaa
#Ver: 0.11a
import os
import sys
if(len(sys.argv) != 2):
print "Kasutamine: %s <kaust>" % sys.argv[0]
exit(255)
path=sys.argv[1]
dir=os.listdir(path)
for fname in dir:
if (os.path.exists(fname) == False) and (os.path.islink(fname) == True):
print path+fname