Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@adejones
Last active November 26, 2015 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adejones/28ad40634a35067e21b0 to your computer and use it in GitHub Desktop.
Save adejones/28ad40634a35067e21b0 to your computer and use it in GitHub Desktop.
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