#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import pexpect
import sys
import datetime
import os
BASE_DIR = os.path.dirname(os.path.realpath(__file__))
user = "Administrator"
passwd = "password"
def ssh_cmd(ip, cmd):
ssh = pexpect.spawn('ssh %s@%s "%s"' % (user,ip,cmd))
try:
i = ssh.expect(['password:', 'continue connecting (yes/no)?'], timeout=5)
if i == 0 :
ssh.sendline(passwd)
elif i == 1:
ssh.sendline('yes')
ssh.expect('password: ')
ssh.sendline(passwd)
except pexpect.EOF:
print("EOF")
except pexpect.TIMEOUT:
print("TIMEOUT")
else:
r = ssh.read()
print(r)
ssh.close()
if __name__ == '__main__':
file_path = os.path.join(BASE_DIR, 'ip_list.txt')
file = open(file_path,'r')
ip_list = file.read()
file.close()
for ip in ip_list.split("n"):
if ip:
print("-- %s run:update oli.bin from 5.137 to 5.139 --" %ip)
cmd1 = "load /map1/firmware1/ -source http://192.168.103.254/ilo5_139.bin"
ssh_cmd(ip, 'cmd1')