1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
try:
sshc = paramiko.SSHClient()
sshc.set_missing_host_key_policy(paramiko.AutoAddPolicy())
sshc.connect(hostname=currentIP, username='root', password= passwd)
cmd = "ls -l"
stdin, stdout, stderr = sshc.exec_command(cmd)
sshc.close()
#write in the log file result from the command NTP
scriptLog.write(stderr.read()+'\n')
#SSH connexion excpection handling
except paramiko.AuthenticationException:
scriptLog.write("AuthenticationException\n")
except paramiko.BadHostKeyException:
scriptLog.write("BadHostKeyException\n")
except paramiko.ChannelException:
scriptLog.write("ChannelException\n") |
Partager