<代码> # !/usr/bin/python # - * -编码:utf - 8 - * 导入命令 导入系统 导入的时间 类server_unreache(对象): def __init__(自我,ip_list): 自我。ip_list=ip_list #第一次获取无法ping通的服务器列表 def unreachable_ip_list(自我): 全球unreachable_iplist_one_time unreachable_iplist_one_time=[] get_un_iplist_str="/sbin/fp - u - f {}“.format (ip_list) (地位、get_un_iplist)=commands.getstatusoutput (get_un_iplist_str) 在get_un_iplist.split unreach (“\ n”): unreachable_iplist_one_time.append (unreach) #返回unreachable_iplist_one_time 通过 #对第一次获取无法ping通的服务器列表,在进行3次萍操作,每次操作时间间隔为10秒 def do_3times_fping_unreachable(自我): 全球unreache_3times unreache_3times=[] j的范围(3): 因为我在范围(len (unreachable_iplist_one_time)): get_3times_un_iplist_str="/sbin/fp - u {}“.format (unreachable_iplist_one_time[我]) time . sleep (10) (地位、get_3times_un_iplist)=commands.getstatusoutput (get_3times_un_iplist_str) 打印(时间。Y strftime(“% - % - % d % H: % m: % S”,time.localtime ())) 如果状态!=0和get_3times_un_iplist不在unreache_3times: unreache_3times.append (get_3times_un_iplist) 打印(“{}*,unreache_3times {}“.format (j + 1, unreache_3times[我])) 打印(unreache_3times) 通过 def do_reboot(自我,count=0): 全球do_reboot_cmd do_reboot_cmd=" ipmitool我lanplus - h {} - u UserNmae - p密码底盘权力地位” 因为我在范围(len (unreache_3times)): 数=数+ 1 #打印(计数) 如果数& lt;=2: 打印(“\ n do_reboot_cmd do_reboot_ip: {}: {}“.format (unreache_3times[我],do_reboot_cmd.format (unreache_3times[我].replace(“172年。”,“10”。)))) #打印(“do_reboot_ip unreache_3times[我]) if __name__==癬_main__”: ip_list=sys.argv [1] ds=server_unreache (ip_list) ds.unreachable_ip_list () ds.do_3times_fping_unreachable () ds.do_reboot() 代码>