0

I have a USB disk with a partition labeled "Backup"

I am using the package usbmount which automatically mounts the disk at /media/usb[0-7]

I wish to create a bash script check that the disk with the label of "Backup" is mounted at /media/usb0 before commencing.

To date I have used e2label to both check and update the disk label.

Beyond this I am unsure of the best way to approach this.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Dercni
  • 185
  • 1
  • 2
  • 8

1 Answers1

0

Probably something like

#!/bin/sh
MatchLabel=Backup
CheckPath=/mnt/usb0

realDevice=`readlink -f /dev/disk/by-label/$MatchLabel 2>/dev/null`
mountedDevice=`awk "/ $CheckPath /{print \$1}" /etc/mtab 2>/dev/null`
test "$mountedDevice" && realMountedDevice=`readlink -f $mountedDevice`

if test "$realDevice" = "$realMountedDevice"; then
    echo $MatchLabel mounted to $CheckPath
else
    echo $realMountedDevice was unexpectedly mounted to $CheckPath
fi
SYN
  • 2,793
  • 12
  • 19