我写了一个小脚本来从我的ubuntu机器读取syslog中的NetworkManager数据。 但输出文件似乎是空的,我看不出我做错了什么。 一些帮助将非常感激。
提前致谢:
代码:
#!/usr/bin/python
import os
import os.path
o = open("/home/user/Desktop/Python/log.txt", "w") #yourdestinationfolder
if os.path.exists("/var/log/messages"): #messages in ubuntu is no more
f = open("/var/log/messages", "r")
for line in f.readlines():
if "NetworkManager" in line:
o.write(line)
if os.path.exists("var/log/syslog"):
d = open("/var/log/syslog" , "r")
for line in d.readline():
if "NetworkManager" in line:
o.write(line)
来自syslog的片段
cat syslog | grep NetworkManager
Nov 12 16:38:33 root-garlic NetworkManager[1134]: <info> [1478965113.9672] device (wlx00116b4ee031): state change: unmanaged -> unavailable (reason 'managed') [10 20 2]
Nov 12 16:38:33 root-garlic kernel: [ 1291.985246] IPv6: ADDRCONF(NETDEV_UP): wlx00116b4ee031: link is not ready
Nov 12 16:38:33 root-garlic kernel: [ 1291.985278] ieee80211 phy0: rt2x00lib_request_firmware: Info - Loading firmware file 'rt2870.bin'
Nov 12 16:38:33 root-garlic kernel: [ 1291.985344] ieee80211 phy0: rt2x00lib_request_firmware: Info - Firmware detected - version: 0.29
Nov 12 16:38:36 root-garlic ModemManager[1071]: <info> Couldn't find support for device at '/sys/devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-1': not supported by any plugin
Nov 12 16:38:36 root-garlic kernel: [ 1294.102790] IPv6: ADDRCONF(NETDEV_UP): wlx00116b4ee031: link is not ready
Nov 12 16:38:36 root-garlic wpa_supplicant[1629]: dbus: wpa_dbus_get_object_properties: failed to get object properties: (none) none
Nov 12 16:38:36 root-garlic wpa_supplicant[1629]: dbus: Failed to construct signal
Nov 12 16:38:36 root-garlic NetworkManager[1134]: <info> [1478965116.1538] device (wlx00116b4ee031): supplicant interface state: starting -> ready
Nov 12 16:38:36 root-garlic NetworkManager[1134]: <info> [1478965116.1540] device (wlx00116b4ee031): state change: unavailable -> disconnected (reason 'supplicant-available') [20 30 42]
Nov 12 16:38:36 root-garlic kernel: [ 1294.172125] IPv6: ADDRCONF(NETDEV_UP): wlx00116b4ee031: link is not ready
Nov 12 16:38:38 root-garlic wpa_supplicant[1629]: wlx00116b4ee031: CTRL-EVENT-REGDOM-CHANGE init=BEACON_HINT type=UNKNOWN
Nov 12 16:38:39 root-garlic wpa_supplicant[1629]: wlx00116b4ee031: CTRL-EVENT-REGDOM-CHANGE init=BEACON_HINT type=UNKNOWN
Nov 12 16:38:39 root-garlic NetworkManager[1134]: <info> [1478965119.4021] device (wlx00116b4ee031): supplicant interface state: ready -> inacti