Cloud

windows winrm 을 사용한 log 관리 본문

인프라관리-코드

windows winrm 을 사용한 log 관리

Firewall 2023. 7. 27. 10:54

#!/usr/bin/env python3 -u

import winrm

hosts = {'$hostname':'$ip'}
user_id = '$id'
user_pw = '$password'

file_compress_cmd = '''
e:\gamepub\cygwin\cygnative find /cygdrive/e/game/servers -type f -name "*.log" -mtime +2 -mtime -5 -exec 'gzip -v' {} ;
'''

file_move_cmd = '''
e:\game\cygwin\cygnative rsync -av --include=*.log.gz --exclude=*.* --remove-source-files /cygdrive/e/game/servers/* /cygdrive/f/logbackup/
'''

def run_windows_cmd(cmd):
    result_byte = session.run_cmd(cmd)
    print(result_byte.std_out.decode('utf-8'))
    return

for hostname, ip in hosts.items():
    print(hostname, ip)
    session = winrm.Session(ip, auth=(user_id, user_pw))
    run_windows_cmd(file_compress_cmd)
    run_windows_cmd(file_move_cmd)
Comments