【问题标题】:Keep track of the terminal output of a booting router device跟踪引导路由器设备的终端输出
【发布时间】:2019-05-22 06:37:24
【问题描述】:

我正在开发一个 python 脚本,它重新启动一个 cisco 路由器(接入点),我想捕获启动日志。

但我无法获取reboot log

当设备重启时,我尝试过以这种方式使用子进程模块:

output=subprocess.Popen(ap1.reload_ap(), stdout=subprocess.PIPE).communicate()[0]

ap1.reload_ap() 将重新启动设备,但不会返回任何内容。

所以我尝试将进程输出重定向到标准输出,以便在通过subprocess.PIPE 执行脚本后在终端上显示启动日志。

但是我无法使用子进程跟踪此启动日志。

有什么方法可以将 AP 启动日志捕获到终端或以其他方式?

【问题讨论】:

    标签: python process operating-system


    【解决方案1】:

    重新启动系统从系统/内核调用reboot 开始,这就是您的进程所做的一切,整个重新启动的事情发生在内核空间中,这确实超出了您的 Python 脚本的范围,该脚本在用户空间。

    所以:

    output=subprocess.Popen(ap1.reload_ap(),stdout=subprocess.PIPE).communicate()[0]
    

    您将只能看到 reboot 系统调用的输出,没有别的。

    另一方面,您的 Python 解释器在系统关闭所有进程之前终止的可能性非常高。

    您应该阅读How does the system shutdown of a Linux kernel work internally? 以获得更好的理解。

    另类

    您无法以您想要的方式获取日志,但系统仍会生成日志,因此您可以在重启完成后使用 Python 读取此类日志。这可能会有所帮助:How to find out from the logs what caused system shutdown?

    推荐阅读。

    What is difference between User space and Kernel space?

    【讨论】:

      猜你喜欢
      • 2011-01-12
      • 2020-07-24
      • 2022-11-01
      • 1970-01-01
      • 2014-12-10
      • 1970-01-01
      • 2022-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多