$ (mountpoint -q "/media/mpdr1" && df /media/mpdr1/* > /dev/null 2>&1) || ((sudo umount "/media/mpdr1" > /dev/null 2>&1 || true) && (sudo mkdir "/media/mpdr1" > /dev/null 2>&1 || true) && sudo mount "/dev/sdd1" "/media/mpdr1")
In my example, the mount point is /media/mpdr1 and the FS is /dev/sdd1
/mountpoint-path = /media/mpdr1
filesystem=/dev/sdd1
Why this command ?
Well, in fact, with some external devices I used to face some issues : during data transfer from the device to the internal drive, some errors occurred and the device was unmounted and remounted again in a different folder.
In such situations, the command mountpoint gave a positive result even if the FS wasn't properly mounted, that's why I added the df part.
And if the device is not properly mounted, the command tries to unmount, to create the folder (if it exists already it will also work) and finally mount the FS on the given mount point.
by David Winterbottom (codeinthehole.com)
0sem comentários ainda