Last active
November 26, 2015 16:40
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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