User:Rsepp: Difference between revisions

From ICO wiki
Jump to navigationJump to search
Rsepp (talk | contribs)
No edit summary
Rsepp (talk | contribs)
No edit summary
Line 39: Line 39:


   
   
import sys,os,commands
import sys,os


#Õiguste kontroll
#Õiguste kontroll

Revision as of 09:40, 24 May 2011

#!/bin/bash
#Autor: Rene Sepp A21
#Skript kontrollib, kas Ubuntu serveris on seadistatud etteantud IP alias

IP=$1

#Õiguste kontroll
if [ $UID -ne 0 ]; then
echo "Käivita skript $(basename $0) rootkasutaja õigustega"
exit 1
 
fi
 
#Kontrollib kas IP on parameetrina antud 
if [ $# -ne 1 ]; then
        echo "Käivita skript $(basename $0) koos IP-ga"
        exit 1
fi

#Otsib failist '/etc/network/interfaces' argumendis antud IP vastet ja võrdleb seda argumendis antud IP-ga
if [ $IP = $(grep $IP '/etc/network/interfaces' | cut -d"s" -f3 | cut -d" " -f2  | sort -u) ]; then
        echo "alias olemas"
        exit 0
else
        echo "aliast pole"
        exit 1
fi


#!/usr/bin/python
# -*- coding: utf-8 -*-
#Autor: Rene Sepp A21
#Versioon: 0.1
#Skript kontrollib, kas Ubuntu serveris on seadistatud etteantud IP alias
#Kasutamine: alias.py <IP> 

 
import sys,os

#Õiguste kontroll
if os.geteuid() != 0:
    print "Käivita skript rootkasutaja õigustega"
    sys.exit(1)

#Etteantud parameetrite kontroll
if len(sys.argv) != 2:
    print "Käivita skript %s parameetritega : koos IP-ga"
    sys.exit(1)

IP = (sys.argv[1])

fh=file("/etc/network/interfaces")

found = False
for line in fh:
    if "address " + IP in line:
        found = True
        break
if found == True:
    print "Alias olemas"
    sys.exit(0)
else:
    print "Alias puudub"
    sys.exit(1)