Hello,<br><br>I'm trying to mount an usb device from python under linux.<br>To do so, I read the kernel log /proc/kmsg and watch for something like:<br> "<6> /dev/scsi/host3/bus0/target0/lun0/:<7>usb-storage: device scan complete"
<br><br>When I compile a regular expression like:<br> "r = re.compile('<\d+>\s/dev/scsi/host\d+/bus\d+/target\d+/lun\d+')"<br>It is found. But I don't want the <\d+>\s or '<6> ' in front of the path, so I tried:
<br> "r = re.compile('/dev/scsi/host\d+/bus\d+/target\d+/lun\d+')"<br>But this way the usb device path it is not found.<br><br>So what i'm trying to do is:<br>- find the usb device path from the kernel log with the regular expression.
<br>- Determine the start and end positions of the match (and add /disc or /part1 to the match).<br>- And use that to mount the usb stick on /mnt/usb -> mount -t auto match /mnt/usb<br><br>If anyone can see what i'm doing wrong, please tell me, because I don't understand it anymore.
<br>Thanks.<br><br>Below is the code:<br><br># \d+ = 1 or more digits<br>
# \s = an empty space<br><br>import re<br><br>def findusbdevice():<br> ''' Returns path of usb device '''<br> # I did a 'cat /proc/kmsg /log/kmsg' to be able to read the kernel message.<br> # Somehow I can't read /proc/kmsg directly.
<br> kmsg = open('/log/kmsg', 'r') <br> r = re.compile('/dev/scsi/host\d+/bus\d+/target\d+/lun\d+')<br> #r = re.compile('<\d+>\s/dev/scsi/host\d+/bus\d+/target\d+/lun\d+')<br> for line in kmsg:<br> if 'usb-storage' in line and
r.match(line):<br> print 'Success', line<br>