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>&nbsp; &quot;&lt;6&gt; /dev/scsi/host3/bus0/target0/lun0/:&lt;7&gt;usb-storage: device scan complete&quot;
<br><br>When I compile a regular expression like:<br>&nbsp; &quot;r = re.compile('&lt;\d+&gt;\s/dev/scsi/host\d+/bus\d+/target\d+/lun\d+')&quot;<br>It is found. But I don't want the &lt;\d+&gt;\s or '&lt;6&gt; ' in front of the path, so I tried:
<br>&nbsp;&nbsp; &quot;r = re.compile('/dev/scsi/host\d+/bus\d+/target\d+/lun\d+')&quot;<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 -&gt; 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&nbsp; = an empty space<br><br>import re<br><br>def findusbdevice():<br>&nbsp;&nbsp;&nbsp; ''' Returns path of usb device '''<br>&nbsp;&nbsp;&nbsp; # I did a 'cat /proc/kmsg /log/kmsg' to be able to read the kernel message.<br>&nbsp;&nbsp;&nbsp; # Somehow I can't read /proc/kmsg directly.
<br>&nbsp;&nbsp;&nbsp; kmsg = open('/log/kmsg', 'r') <br>&nbsp;&nbsp;&nbsp; r = re.compile('/dev/scsi/host\d+/bus\d+/target\d+/lun\d+')<br>&nbsp;&nbsp;&nbsp; #r = re.compile('&lt;\d+&gt;\s/dev/scsi/host\d+/bus\d+/target\d+/lun\d+')<br>&nbsp;&nbsp;&nbsp; for line in kmsg:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if 'usb-storage' in line and 
r.match(line):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print 'Success', line<br>