rfii
rfii

Reputation: 593

Linux usbmount: Determining Which Mounting Points Are Truly Active

Running Rasbian Buster Lite headless no desktop, I am using usbmount to automount usb storage drives. By default it sets them to /media/usb0, /media/usb1, ... /media/usb7; however, these mount points exist whether there is any usb drive in at all. I can even write files to these folders when nothing is plugged in and see them with ls. My question is how can I determine whether these mount points are real or not

Background: Trying to make a script that saves files to USB sticks without any user intervention other than plugging a usb drive in and swapping it out later with a new usb stick.

Linux novice, so would appreciate any extra explanation that can be offered.

Thanks!

Upvotes: 0

Views: 386

Answers (1)

Philippe
Philippe

Reputation: 26377

Currently active mount points can be determined by :

#!/usr/bin/env bash

while read -r real on mount _; do
    if  fdisk -l | grep -q "^$real"; then
        echo "$real is mounted on $mount"
    fi
done < <(mount | grep "on /media")

Save above script in test.sh, then run

chmod +x test.sh
./test.sh

Upvotes: 1

Related Questions