我尝试了下面的代码,它没有重新启动我的远程电脑。
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")
if(os.system(rebootsys %locals())==0
它只是空闲的,它不会移动到下一步,如果它重新启动,那么它必须移动print("Done")
,否则它必须移动其他部分,而只是等待if条件本身。我需要通过python脚本从我的ubuntu系统重新启动多个ubuntu系统。
我建议切换到^{} 模块,捕捉启动的命令的输出,然后决定下一步如何处理启动的进程。假设现在使用
system()
不是一个好的实践,原因很多,从优雅到安全。在这个模块真正能做什么的好例子在17.1.4.3. Replacing os.system()和17.1.4.5. Replacing os.popen(), os.popen2(), os.popen3()部分。相信我,使用它值得多写几行代码:-)
相关问题 更多 >
编程相关推荐