重新启动远程系统不工作?

2024-09-30 18:18:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试了下面的代码,它没有重新启动我的远程电脑。

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"),否则它必须移动其他部分,而只是等待if条件本身。我需要通过python脚本从我的ubuntu系统重新启动多个ubuntu系统。

Tags: theipifisos系统line条件
1条回答
网友
1楼 · 发布于 2024-09-30 18:18:38

我建议切换到^{}模块,捕捉启动的命令的输出,然后决定下一步如何处理启动的进程。假设现在使用system()不是一个好的实践,原因很多,从优雅到安全。在

这个模块真正能做什么的好例子在17.1.4.3. Replacing os.system()17.1.4.5. Replacing os.popen(), os.popen2(), os.popen3()部分。相信我,使用它值得多写几行代码:-)

相关问题 更多 >