Skip to content

Instantly share code, notes, and snippets.

@stuudmuffin
Last active February 28, 2024 01:26
Show Gist options
  • Save stuudmuffin/a639f24ea09b289d88a2b08a33d93565 to your computer and use it in GitHub Desktop.
Save stuudmuffin/a639f24ea09b289d88a2b08a33d93565 to your computer and use it in GitHub Desktop.
simple exfat mounting script with some error checking
#!/bin/bash
# I had this on an ubuntu box which had a USB hard drive for some basic server backups.
# this could be easily modified for other mounting types.
# REQUIREMENTS:
# install exfat compatability
# find the uuid of your drive (I used "ls -l /dev/disk/by-uuid" then "smartctl -i /dev/PATH_HERE" to determine which drive I was wanting
uuid="5566-77FF"; # the uuid can sometimes be longer.
mnt_path="/mount/exfat"; # mnt_path can be just about any empty folder you'd like. And it must be empty to work.
if [ ! -d $mnt_path ]; then
mkdir -p $mnt_path;
fi
bogus="../../"; # the $path later on will have this, and we don't want it, so we'll strip it :)
drive_lookup=`ls -l /dev/disk/by-uuid | grep $uuid | awk '{ print $9 }'`;
if [ "$drive_lookup" ]; then
path=`ls -l /dev/disk/by-uuid | grep $uuid | awk '{ print $11 }'`;
path=${path#$bogus};
echo "drive has uuid:$drive_lookup and is locted in $path";
if grep -qs "/dev/$path" /proc/mounts; then
echo "It's already mounted.";
else
if [ "$(ls -A $mnt_path)" ]; then
echo 'path "'.$mnt_path.'" is not empty! Unable to mount drive';
exit 1;
fi
echo "It's not mounted. Mounting drive now...";
mount -t exfat /dev/$path $mnt_path;
echo "But it should be now!";
fi
else
echo "drive not found";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment