import paramiko
import os, time, subprocess
port = "22"
username = ""
password = ""
f = open("hosts.txt", "r")
for ip in f:
print(ip)
#print(ip.strip())
cmd = "sshpass -p '' scp -r /home/raghuvel.sekar/deployAgentbkp.py root@{}:/home/raghuvel.sekar".format(ip.strip())
#print (cmd)
jobout= subprocess.check_output(cmd, shell=True)
time.sleep(10)
#print (jobout)
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip,port,username,password)
stdin,stdout,stderr=ssh.exec_command('(cd /home/raghuvel.sekar; python test.py)')
time.sleep(10)
outlines=stdout.readlines()
resp =''.join(outlines)
print("done")
No comments:
Post a Comment