I’m using debian with usbmount. I want to check if a USB memory stick is available to write to.
Currently I check if a specific dir exists on the USB drive. If this is True I can then write the rest of my files – os.path.isdir('/media/usb0/Test_Folder')
I would like to create Test_Folder if it doesn’t exist. However /media/usb0/ exists even if no USB device is there so I can’t just os.mkdir('/media/usb0/Test_Folder') As it makes the file locally.
I need a check that there is a usb drive available on /media/usb0/ to write to before creating the file. Is there a quick way of doing this?
cat /etc/mtab | awk '{ print $2 }'Will give you a list of mountpoints. You can as well read /etc/mtab yourself and just check if anything’s mounted under /media/usb0 (file format: whitespace-divided, most likely single space). The second column is mount destination, the first is the source.