넷백업은 각 폴리시 별로 백업 대상디렉토리가 정해지는데

아래와 같은 코드를 사용하면 각 폴리시에서 어떤 폴더들이 백업대상 폴더로 세팅되었는지 알수 있다.

import commands

def get_policy_list():
    lines=commands.getoutput('bppllist').split('\n')
    return lines

def get_include_dir(policies):
    backup_target={}
    print policies
    for policy in policies:
        if policy != 'ORACLE_ARCHIVE':
            dirs=[]
            includes=commands.getoutput('bpplinclude %s -L'% policy).split('\n')
            for include in includes:
                dir=(include.split(':')[-1]).strip()
                dirs.append(dir)
            if( dirs.count('CATALOG_DRIVEN_BACKUP') == 0):
                backup_target[policy]=dirs
            else:
                pass
    for line in backup_target.keys():
        print line,backup_target[line]

policies=get_policy_list()
get_include_dir(policies)

이번엔 간단히 소켓 프로그래밍을 만들어 보겠습니다.

방법은 다른 OS들의 C라이브러리를 사용하는 것과 크게 다르지 않고 설정하는 부분도 대부분 동일한 형태입니다.

기본적으로 서버는 응답을 기다리고 응답이 오면 다시 해당 응답을 클라이언트로 전달하는 ECHO서버 예제입니다.

일단 Server쪽 먼저 만들어 보겠습니다. (소스는 python doc에서 인용하였습니다.)

# Echo server program
import socket

HOST = ''                   # Symbolic name meaning all available interfaces
PORT = 50007              # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
while 1:
    data = conn.recv(1024)
    if not data: break
    conn.sendall(data)
conn.close()

크게 어렵지 않은 부분이라고 생각되어 집니다. 사실 몰라도 되죠 그냥 저렇게 써 주면 됩니다.

나중에 시간이 되면 라인 단위로 설명을 드리도록 하겠습니다.

다음 부분은 클라이언트 부분입니다.

# Echo client program
import socket

HOST = 'IP '                # The remote host
PORT = 50007              # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.sendall('Hello, world')
data = s.recv(1024)
s.close()
print 'Received', repr(data)

위의 IP부분에 서버의 IP를 입력해주면 바로 동작이 되는 것을 확인할 수 있습니다.

이상입니다. 결과는 소스를 바로 가져 가시면 확인이 가능합니다. 제가 확인을 해보았습니다.

import subprocess
cmd = 'ls -al'
subprocess.call(cmd,shell=True)


drwxrwxr-x 2 root games       4096 Jun 28 12:45 linux_x86_64
-rw-r--r-- 1 root root        5235 Sep 15 08:02 install.log.syslog
-rw-r--r-- 1 root root       60894 Sep 15 08:02 install.log
-rw------- 1 root root        2285 Sep 15 08:02 anaconda-ks.cfg
drwxr-xr-x 2 root root        4096 Sep 15 08:20 Desktop

import os

cmd = 'ls -al'

os.system(cmd) 


total 1571540
drwxr-x--- 26 root root        4096 Oct  4 01:22 .
drwxr-xr-x 33 root root        4096 Sep 20 01:17 ..
-rw-r--r--  1 root root  1462227520 Sep 17 01:45 ABR11A_ko-KR.exe
-rw-------  1 root root        2285 Sep 15 08:02 anaconda-ks.cfg
-rw-------  1 root root       16332 Sep 27 23:52 .bash_history
-rw-r--r--  1 root root          24 Jul 13  2006 .bash_logout
-rw-r--r--  1 root root         364 Sep 16 02:34 .bash_profile
-rw-r--r--  1 root root        1276 Sep 16 02:33 .bashrc
-rwxr-xr-x  1 root root          40 Oct  4 01:22 cmd.py

너무 간단한가요??

import socket

socket.gethostbyname(socket.getfqdn())

import commands

ETHER_NAME=0
HEADER=2

result=commands.getoutput('netstat -ni').split('\n')[HEADER:]
ether_name=[]
for line in result:
    ether=line.split()[ETHER_NAME]
    if ether != 'lo':
        ether_name.append(ether)
print ether_name


['eth0', 'eth1']

#!/usr/bin/env python
from socket import *

if __name__ == '__main__':
    target = raw_input('Enter host to scan: ')
    targetIP = gethostbyname(target)
    print 'Starting scan on host ', targetIP

    #scan reserved ports
    for i in range(20, 1025):
        s = socket(AF_INET, SOCK_STREAM)

        result = s.connect_ex((targetIP, i))

        if(result == 0) :
            print 'Port %d: OPEN' % (i,)
        s.close()


~$ ./scanner.py
Enter host to scan: localhost
Starting scan on host  127.0.0.1
Port 22: OPEN
Port 80: OPEN
Port 139: OPEN
Port 445: OPEN
Port 631: OPEN

from Tkinter import *
import time
def donothing():
   filewin = Toplevel(root)
   button = Button(filewin, text="Do nothing button")
   button.pack()

def input_dev():
   frame_input=Frame(base_frame)
   frame_input.pack(side=TOP)
   lable_input=Label(frame_input,text="input Frame")
   lable_input.pack()

def remove_dev():
   base_frame.destroy()
  
root = Tk()
root.title('JAEHOON NMS')
menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Add Device", command=input_dev)
filemenu.add_command(label="Remove Device", command=remove_dev)
filemenu.add_command(label="View all device", command=donothing)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)

menubar.add_cascade(label="Device", menu=filemenu)

editmenu = Menu(menubar, tearoff=0)
editmenu.add_command(label="Check Ping", command=donothing)
editmenu.add_command(label="Check Cpu/Mem", command=donothing)

menubar.add_cascade(label="Monitor", menu=editmenu)

helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label="Help Index", command=donothing)
helpmenu.add_command(label="About...", command=donothing)

menubar.add_cascade(label="Help", menu=helpmenu)

base_frame=Frame(root, width=500, height=300)
base_frame.pack(fill='both',expand='yes')
base_lable_ip=Label(base_frame, text='IP').grid(row=0,column=0)
base_lable_os=Label(base_frame, text='OS').grid(row=0,column=1)
base_lable_memory=Label(base_frame, text='Memory').grid(row=0,column=2)
ip=Entry(base_frame,text='11.4.14.71')
os=Entry(base_frame)
memory=Entry(base_frame)
ip.grid(row=1,column=0)
os.grid(row=1,column=1)
memory.grid(row=1,column=2)
root.config(menu=menubar)
root.mainloop()

'PYTHON > CODE' 카테고리의 다른 글

[CODE] 현재 사용중인 interface name 가져오기  (0) 2012.09.27
[CODE] Port Scanner 예제  (0) 2012.09.26
[CODE] 시스템 정보 가져오기  (0) 2012.09.24
[CODE] ID/PASSWD 복잡성 체크  (0) 2012.09.24
[CODE] 디스크 사용량 체크  (0) 2012.09.24

#!/usr/bin/python

import os
import time

unumber = os.getuid()
pnumber = os.getpid()
where = os.getcwd()
what = os.uname()
used = os.times()
now = time.time()
means = time.ctime(now)

print "User number",unumber
print "Process ID",pnumber
print "Current Directory",where
print "System information",what
print "System information",used

print "\nTime is now",now
print "Which interprets as",means

'PYTHON > CODE' 카테고리의 다른 글

[CODE] Port Scanner 예제  (0) 2012.09.26
[CODE] TKINTER 메뉴 만들기  (0) 2012.09.24
[CODE] ID/PASSWD 복잡성 체크  (0) 2012.09.24
[CODE] 디스크 사용량 체크  (0) 2012.09.24
[CODE] 특정 파일을 검색해 권한 출력하기  (0) 2012.09.24

import pwd

#initialize counters
erroruser = []
errorpass = []

#get password database
passwd_db = pwd.getpwall()

try:
    #check each user and password for validity
    for entry in passwd_db:
        username = entry[0]
        password = entry [1]
        if len(username) < 6:
            erroruser.append(username)
        if len(password) < 8:
            errorpass.append(username)

    #print results to screen
    print "The following users have an invalid userid (less than six characters):"
    for item in erroruser:
        print item
    print "\nThe following users have invalid password(less than eight characters):"
    for item in errorpass:
        print item
except:
    print "There was a problem running the script."

'PYTHON > CODE' 카테고리의 다른 글

[CODE] Port Scanner 예제  (0) 2012.09.26
[CODE] TKINTER 메뉴 만들기  (0) 2012.09.24
[CODE] 시스템 정보 가져오기  (0) 2012.09.24
[CODE] 디스크 사용량 체크  (0) 2012.09.24
[CODE] 특정 파일을 검색해 권한 출력하기  (0) 2012.09.24

+ Recent posts