python pexpect, paramiko 라이브러리를 이용한 원격지 서버의 명령어 수행
1) pip 설치
2) pip install pexepect, paramiko
#!/usr/bin/python
####################################
import pexpect
import paramiko
import time
import sys
def ssh_conn(host,passwd,command):
result=""
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host,username='root',password=passwd)
stdin, stdout, stderr = ssh.exec_command(command)
for i in stdout.readlines():
result+=i
print result
ssh.close()
return result
if __name__ == "__main__":
try:
num = 1
mgmt = ""
networks = ["172.16.193.", "172.16.194.", "172.16.196.", "172.16.197."]
for i in networks:
print i + "X MGMT Network POD " + "\n"
for j in range(1,9):
mgmt = i + str(j)
ssh_conn(mgmt, "password", sys.argv[1])
time.sleep(1)
except Exception, e:
print str(e)
'Python_Study' 카테고리의 다른 글
[python] pass, continue 차이 (2) | 2015.09.23 |
---|---|
[python] class , self (0) | 2015.09.10 |
python pip (0) | 2015.08.21 |
Flask 정리 (0) | 2015.02.05 |
52장 카드만들기 (0) | 2014.08.20 |