User:Rsepp: Difference between revisions
From ICO wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 27: | Line 27: | ||
exit 1 | exit 1 | ||
fi | fi | ||
</source> | |||
<source lang="python"> | |||
#!/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,commands | |||
#Õ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 IP in line: | |||
found = True | |||
break | |||
if found == True: | |||
print "Alias olemas" | |||
sys.exit(0) | |||
else: | |||
print "Alias puudub" | |||
sys.exit(1) | |||
</source> |
Revision as of 20:57, 23 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,commands
#Õ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 IP in line:
found = True
break
if found == True:
print "Alias olemas"
sys.exit(0)
else:
print "Alias puudub"
sys.exit(1)