我尝试了下面的代码,它没有重新启动我的远程电脑。
for line in readips.readlines():
line = line.strip()
print("The ip address is : ") + str(line)
rebootsys = "ssh root@"+str(line) + " reboot"
print("The reboot system ip is:") + str(rebootsys)
if(os.system(rebootsys %locals())==0):
print("Done")
else:
print("Not able to reboot")
执行 print 语句时成功打印 IP。我是使用wing IDE一步一步运行的。当系统开始执行 if 条件
if(os.system(rebootsys %locals())==0
时它只是空闲,它不会进入下一步,如果它重新启动则必须移动print("Done")
else 它必须移动 else 部分,而只是等待 if 条件本身。我需要通过 python 脚本从我的 ubuntu 系统重新启动多个 ubuntu 系统。