I regularly copy some files using rsync to USB Flash Drives and eSATA HDDs and don't want to use the web interface to unmount the drive when the copy is finished, so I run the script attached to this post.
Simply copy the attached file to the Public share, and then move it on a directory on your PATH, e.g. /opt/bin in this way:
Code: Select all
[~] # cd /share/Public
[/share/Public] # tar zxf uumount.tar.gz -C /opt/bin/
To use it and unmount a device, simply type:
Code: Select all
[~] # uumount
Select the drive to unmount:
1) eSATADisk1
Drive to unmount (or 'q' to quit)?
Alternatively, you can unmount a device directly, for example:
Code: Select all
[~] # uumount USBDisk1
Code: Select all
#!/bin/sh
# Unmount a folder (e.g. 'USBDisk1')
function unmount_folder() {
if [ -d "/share/$1" ]; then
# Remove Samba share
/sbin/smbtools -k $1
# Unmount the drive
/bin/umount /share/$1
# Remove the shared folder
/bin/rm /share/$1
# Remove the Samba configuration
/sbin/rmcfg $1 -f /etc/smb.conf
# Success
/bin/echo "Successfully unmounted '/share/$1'."
else
# Error during unmounting
/bin/echo "Unable to find '/share/$1' share." >&2
exit 1
fi
}
# Unmount a USB/eSata disk
if [ ! -z "$1" ]; then
# Unmount the share specified
unmount_folder $1
else
# Display menu, if necessary
# Get mounted dirs
mounted_dirs=()
for dir in /share/USBDisk* /share/eSATADisk*
do
if [ -d "$dir" ]; then
mounted_dirs+=("${dir##*/}")
fi
done
# Check if there are mounted dirs
if [ ${#mounted_dirs[@]} -gt 0 ]; then
# Display menu
/bin/echo "Select the drive to unmount:"
# Set the prompt
PS3="Drive to unmount (or 'q' to quit)? "
# Show the menu
select drive in "${mounted_dirs[@]}"
do
if [ ! -z "$drive" ]; then
unmount_folder $drive
fi
break
done
else
# No mounted drives
/bin/echo "No mounted drives to unmount." >&2
fi
fi