Skip to content

Instantly share code, notes, and snippets.

@adejones
Last active Nov 26, 2015
Embed
What would you like to do?
Check a mount point on Linux, attempt some recovery if the directory contains files then attempt mount -a
#!/usr/bin/env sh
# check if share is mounted, attempt recovery and remount
if [ -z "$1" ]; then
echo "Usage: $0 /mount/point/to/check"
exit 0
fi
DIR="$1"
if grep -qs "$DIR" /proc/mounts; then
# echo "$DIR is mounted."
exit 0
else
echo "$DIR is not mounted."
if [ "$(ls -A $DIR)" ]; then
NEWDIR="$DIR-`date +%F-%k-%M-%S`"
echo "Files exist so renaming $DIR -> $NEWDIR"
mv "$DIR" "$NEWDIR"
mkdir -p "$DIR"
fi
echo "Attempt remount..."
mount -a
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment