System: Linux Mint 19.1 Cinnamon 64-bit, based on Ubuntu 18.04 LTS.
I would like to know if it is possible to get the following information:
Is this UUID (of a block device) mounted or not? (without knowing the mount point)
In spite, I have played along with this half a day, I can't figure it out.
I have at least created some working code below which un-mounts and powers off both of the USB hard drives.
The current, temporary, version of my code looks like this:
dismount_and_poweroff_external_drives()
{
name_external_drive_500gb_ntfs='500GB NTFS USB 2.0 HDD'
name_external_drive_2_0tb_ext4='2.0TB Ext4 USB 3.0 HDD'
uuid_external_drive_500gb_ntfs='xxxxxxxxxxxxxxxx' # censored
uuid_external_drive_2_0tb_ext4='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # censored
path_external_drive_500gb_ntfs="/dev/disk/by-uuid/${uuid_external_drive_500gb_ntfs}"
path_external_drive_2_0tb_ext4="/dev/disk/by-uuid/${uuid_external_drive_2_0tb_ext4}"
tput bold; tput setaf 3; printf '%b' "\\n${name_external_drive_500gb_ntfs} un-mount\\n"; tput sgr0
# info test ‘-b FILE’: True if FILE exists and is a block special device.
if [ ! -b "${path_external_drive_500gb_ntfs}" ]
then
tput bold; tput setaf 4; printf '%b' "The device is not plugged in or powered on.\\n"; tput sgr0
else
if umount "${path_external_drive_500gb_ntfs}"
then
tput bold; tput setaf 2; printf '%b' "Un-mounting OK.\\n"; tput sgr0
if udisksctl power-off --block-device "${path_external_drive_500gb_ntfs}"
then
tput bold; tput setaf 2; printf '%b' "Powering-off OK.\\n"; tput sgr0
else
tput bold; tput setaf 1; printf '%b' "Powering-off Failed.\\n"; tput sgr0
fi
else
tput bold; tput setaf 1; printf '%b' "Un-mounting Failed.\\n"; tput sgr0
fi
fi
printf '\n'
tput bold; tput setaf 3; printf '%b' "\\n${name_external_drive_2_0tb_ext4} un-mount\\n"; tput sgr0
# info test ‘-b FILE’: True if FILE exists and is a block special device.
if [ ! -b "${path_external_drive_2_0tb_ext4}" ]
then
tput bold; tput setaf 4; printf '%b' "The device is not plugged in or powered on.\\n"; tput sgr0
else
if umount "${path_external_drive_2_0tb_ext4}"
then
tput bold; tput setaf 2; printf '%b' "Un-mounting OK.\\n"; tput sgr0
if udisksctl power-off --block-device "${path_external_drive_2_0tb_ext4}"
then
tput bold; tput setaf 2; printf '%b' "Powering-off OK.\\n"; tput sgr0
else
tput bold; tput setaf 1; printf '%b' "Powering-off Failed.\\n"; tput sgr0
fi
else
tput bold; tput setaf 1; printf '%b' "Un-mounting Failed.\\n"; tput sgr0
fi
fi
printf '\n'
}
I forgot to stress that the accepted solution must be POSIX-ly written.