Realization of python monitoring usb device signal under linux
- 2021-07-06 11:29:56
- OfStack
1. Message logging under linux
All kinds of messages about the system 1 will generally be recorded in the/var/log/messages file. Some hosts may not be enabled by default. For specific configuration methods, please refer to the following blog:
System Log Configuration/var/log/messages
2. python code implementation
The principle is actually very simple, that is, read the/var/log/messages file and find the information about usb.
#!/usr/bin/env python
usbmsg = open("/var/log/messages", "r")
for line in usbmsg.readlines():
if ("usb" or "USB") in line:
print line
usbmsg.close()