Created
July 3, 2015 11:34
-
-
Save qizhihere/3de7885d850535a9182b to your computer and use it in GitHub Desktop.
check if the specific device has been mounted
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
is_mounted () { | |
if [ $# -eq 1 ]; then | |
if [ ! -b "$1" ]; then | |
echo "error: invalid device:$1" | |
return 1 | |
elif df | awk '{print $1}' | grep "$1" &>/dev/null; then | |
return 0 | |
else | |
return 1 | |
fi | |
elif [ $# -eq 2 ]; then | |
if [ ! -b "$1" ]; then | |
echo "error: invalid device:$1" | |
return 1 | |
elif df | awk '{print $1,$6}' | grep "^$1 $2$" &>/dev/null; then | |
return 0 | |
else | |
return 1 | |
fi | |
else | |
echo "error: invalid arguments" | |
echo "Usage: is_mounted /dev/sdxN [directory]" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment