How to check if a filesystem is mounted with a script

Clash Royale CLAN TAG#URR8PPP
up vote
16
down vote
favorite
I am new at scripting ... I can do very basic stuff, but now I need a hand.
I have a local filesystem that only will be mounted when I need to do a backup.
I'm starting with this.
#!/bin/bash
export MOUNT=/myfilesystem
if grep -qs $MOUNT /proc/mounts; then
echo "It's mounted."
else
echo "It's not mounted."; then
mount $MOUNT;
fi
As I said, I'm very basic at scripting. I heard that you can check the status of the mount command by looking at the return codes.
RETURN CODES
mount has the following return codes (the bits can be ORed):
0 success
1 incorrect invocation or permissions
2 system error (out of memory, cannot fork, no more loop devices)
4 internal mount bug
8 user interrupt
16 problems writing or locking /etc/mtab
32 mount failure
64 some mount succeeded
I don't know how to check that. Any guidance?
bash shell-script mount
add a comment |
up vote
16
down vote
favorite
I am new at scripting ... I can do very basic stuff, but now I need a hand.
I have a local filesystem that only will be mounted when I need to do a backup.
I'm starting with this.
#!/bin/bash
export MOUNT=/myfilesystem
if grep -qs $MOUNT /proc/mounts; then
echo "It's mounted."
else
echo "It's not mounted."; then
mount $MOUNT;
fi
As I said, I'm very basic at scripting. I heard that you can check the status of the mount command by looking at the return codes.
RETURN CODES
mount has the following return codes (the bits can be ORed):
0 success
1 incorrect invocation or permissions
2 system error (out of memory, cannot fork, no more loop devices)
4 internal mount bug
8 user interrupt
16 problems writing or locking /etc/mtab
32 mount failure
64 some mount succeeded
I don't know how to check that. Any guidance?
bash shell-script mount
2
You have a funny dangling; thenin your script.
– Mat
May 17 '12 at 16:18
why are we exporting the MOUNT var and also remove the ";"
– Mike Q
Nov 23 '16 at 21:38
add a comment |
up vote
16
down vote
favorite
up vote
16
down vote
favorite
I am new at scripting ... I can do very basic stuff, but now I need a hand.
I have a local filesystem that only will be mounted when I need to do a backup.
I'm starting with this.
#!/bin/bash
export MOUNT=/myfilesystem
if grep -qs $MOUNT /proc/mounts; then
echo "It's mounted."
else
echo "It's not mounted."; then
mount $MOUNT;
fi
As I said, I'm very basic at scripting. I heard that you can check the status of the mount command by looking at the return codes.
RETURN CODES
mount has the following return codes (the bits can be ORed):
0 success
1 incorrect invocation or permissions
2 system error (out of memory, cannot fork, no more loop devices)
4 internal mount bug
8 user interrupt
16 problems writing or locking /etc/mtab
32 mount failure
64 some mount succeeded
I don't know how to check that. Any guidance?
bash shell-script mount
I am new at scripting ... I can do very basic stuff, but now I need a hand.
I have a local filesystem that only will be mounted when I need to do a backup.
I'm starting with this.
#!/bin/bash
export MOUNT=/myfilesystem
if grep -qs $MOUNT /proc/mounts; then
echo "It's mounted."
else
echo "It's not mounted."; then
mount $MOUNT;
fi
As I said, I'm very basic at scripting. I heard that you can check the status of the mount command by looking at the return codes.
RETURN CODES
mount has the following return codes (the bits can be ORed):
0 success
1 incorrect invocation or permissions
2 system error (out of memory, cannot fork, no more loop devices)
4 internal mount bug
8 user interrupt
16 problems writing or locking /etc/mtab
32 mount failure
64 some mount succeeded
I don't know how to check that. Any guidance?
bash shell-script mount
bash shell-script mount
edited May 17 '12 at 16:18
Mat
38.7k8117125
38.7k8117125
asked May 17 '12 at 15:51
maniat1k
83231833
83231833
2
You have a funny dangling; thenin your script.
– Mat
May 17 '12 at 16:18
why are we exporting the MOUNT var and also remove the ";"
– Mike Q
Nov 23 '16 at 21:38
add a comment |
2
You have a funny dangling; thenin your script.
– Mat
May 17 '12 at 16:18
why are we exporting the MOUNT var and also remove the ";"
– Mike Q
Nov 23 '16 at 21:38
2
2
You have a funny dangling
; then in your script.– Mat
May 17 '12 at 16:18
You have a funny dangling
; then in your script.– Mat
May 17 '12 at 16:18
why are we exporting the MOUNT var and also remove the ";"
– Mike Q
Nov 23 '16 at 21:38
why are we exporting the MOUNT var and also remove the ";"
– Mike Q
Nov 23 '16 at 21:38
add a comment |
5 Answers
5
active
oldest
votes
up vote
14
down vote
accepted
You can check the status code of mount, and most well written executables, with the shell special parameter ?.
From man bash:
? Expands to the exit status of the most recently executed foreground pipeline.
After you run the mount command, immediately executing echo $? will print the status code from the previous command.
# mount /dev/dvd1 /mnt
mount: no medium found on /dev/sr0
# echo $?
32
Not all executables have well defined status codes. At a minimum, it should exit with a success (0) or failure (1) code, but that's not always the case.
To expand on (and correct) your example script, I added a nested if construct for clarity. It's not the only way to test the status code and perform an action, but it's the easiest to read when learning.
#!/bin/bash
mount="/myfilesystem"
if grep -qs "$mount" /proc/mounts; then
echo "It's mounted."
else
echo "It's not mounted."
mount "$mount"
if [ $? -eq 0 ]; then
echo "Mount success!"
else
echo "Something went wrong with the mount..."
fi
fi
For more information on "Exit and Exit Status", you can refer to the Advanced Bash-Scripting Guide.
1
There's no need to export$MOUNT. This script will also break if the filesystem has any character that would undergo wordsplitting (spaces, etc.). You should always quote your expansions.
– Chris Down
May 17 '12 at 18:49
@ChrisDown You're right. I only deleted the obvious dangling ';then'. In the future, feel free to edit my answer to make it more correct.
– George M
May 17 '12 at 19:30
Er... this will still break. You have still not quoted the expansions. On your advice, I'll do it now.
– Chris Down
May 17 '12 at 20:14
I also wouldn't recommend linking to the infamous "Advanced" Bash scripting guide, it's full of errors and will teach people to write bugs, not scripts. BashGuide is a far better alternative.
– Chris Down
May 17 '12 at 20:15
2
@ChrisDown "Word splitting will eat your babies if you don't quote things properly." Words to live by.
– George M
May 17 '12 at 21:25
add a comment |
up vote
29
down vote
Many Linux distros have the mountpoint command. It can explicitly used to check if a directory is a mountpoint. Simple as this:
#!/bin/bash
if mountpoint -q "$1"; then
echo "$1 is a mountpoint"
else
echo "$1 is not a mountpoint"
fi
This approach will fail if you try to check an encfs, since you will stumble into a permission denied error, when run by a non-root user.
– Denys S.
Dec 1 '15 at 8:40
My solution works with encfs.
– Theodore R. Smith
Mar 22 at 16:13
add a comment |
up vote
2
down vote
The easiest way which doesn't require root is:
if $(df | grep -q /mnt/ramdisk); then
fi
or to see if it isn't mounted:
if ! $(df | grep -q /mnt/ramdisk); then
fi
themountcommand doesn't need root access,dfis focused on disc space not on mount points...
– Philippe Gachoud
Nov 28 at 11:04
add a comment |
up vote
1
down vote
One more way:
if [ "$(findmnt $mount_point)" ] ; then
#Do something for positive result (exit 0)
else
#Do something for negative result (exit 1)
fi
Remove those "$()", otherwise you're not testing for exit status, you're testing the output offindmnt(which happens to output something in the true-case and nothing in the false-case, but it's not obviously safe to rely on this behaviour).
– YoungFrog
Nov 2 at 22:36
add a comment |
up vote
0
down vote
Short statements
Check if mounted:
mount|grep -q "/mnt/data" && echo "/mnt/data is mounted; I can follow my job!"
Check if not mounted:
mount|grep -q "/mnt/data" || echo "/mnt/data is not mounted I could probably mount it!"
add a comment |
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
14
down vote
accepted
You can check the status code of mount, and most well written executables, with the shell special parameter ?.
From man bash:
? Expands to the exit status of the most recently executed foreground pipeline.
After you run the mount command, immediately executing echo $? will print the status code from the previous command.
# mount /dev/dvd1 /mnt
mount: no medium found on /dev/sr0
# echo $?
32
Not all executables have well defined status codes. At a minimum, it should exit with a success (0) or failure (1) code, but that's not always the case.
To expand on (and correct) your example script, I added a nested if construct for clarity. It's not the only way to test the status code and perform an action, but it's the easiest to read when learning.
#!/bin/bash
mount="/myfilesystem"
if grep -qs "$mount" /proc/mounts; then
echo "It's mounted."
else
echo "It's not mounted."
mount "$mount"
if [ $? -eq 0 ]; then
echo "Mount success!"
else
echo "Something went wrong with the mount..."
fi
fi
For more information on "Exit and Exit Status", you can refer to the Advanced Bash-Scripting Guide.
1
There's no need to export$MOUNT. This script will also break if the filesystem has any character that would undergo wordsplitting (spaces, etc.). You should always quote your expansions.
– Chris Down
May 17 '12 at 18:49
@ChrisDown You're right. I only deleted the obvious dangling ';then'. In the future, feel free to edit my answer to make it more correct.
– George M
May 17 '12 at 19:30
Er... this will still break. You have still not quoted the expansions. On your advice, I'll do it now.
– Chris Down
May 17 '12 at 20:14
I also wouldn't recommend linking to the infamous "Advanced" Bash scripting guide, it's full of errors and will teach people to write bugs, not scripts. BashGuide is a far better alternative.
– Chris Down
May 17 '12 at 20:15
2
@ChrisDown "Word splitting will eat your babies if you don't quote things properly." Words to live by.
– George M
May 17 '12 at 21:25
add a comment |
up vote
14
down vote
accepted
You can check the status code of mount, and most well written executables, with the shell special parameter ?.
From man bash:
? Expands to the exit status of the most recently executed foreground pipeline.
After you run the mount command, immediately executing echo $? will print the status code from the previous command.
# mount /dev/dvd1 /mnt
mount: no medium found on /dev/sr0
# echo $?
32
Not all executables have well defined status codes. At a minimum, it should exit with a success (0) or failure (1) code, but that's not always the case.
To expand on (and correct) your example script, I added a nested if construct for clarity. It's not the only way to test the status code and perform an action, but it's the easiest to read when learning.
#!/bin/bash
mount="/myfilesystem"
if grep -qs "$mount" /proc/mounts; then
echo "It's mounted."
else
echo "It's not mounted."
mount "$mount"
if [ $? -eq 0 ]; then
echo "Mount success!"
else
echo "Something went wrong with the mount..."
fi
fi
For more information on "Exit and Exit Status", you can refer to the Advanced Bash-Scripting Guide.
1
There's no need to export$MOUNT. This script will also break if the filesystem has any character that would undergo wordsplitting (spaces, etc.). You should always quote your expansions.
– Chris Down
May 17 '12 at 18:49
@ChrisDown You're right. I only deleted the obvious dangling ';then'. In the future, feel free to edit my answer to make it more correct.
– George M
May 17 '12 at 19:30
Er... this will still break. You have still not quoted the expansions. On your advice, I'll do it now.
– Chris Down
May 17 '12 at 20:14
I also wouldn't recommend linking to the infamous "Advanced" Bash scripting guide, it's full of errors and will teach people to write bugs, not scripts. BashGuide is a far better alternative.
– Chris Down
May 17 '12 at 20:15
2
@ChrisDown "Word splitting will eat your babies if you don't quote things properly." Words to live by.
– George M
May 17 '12 at 21:25
add a comment |
up vote
14
down vote
accepted
up vote
14
down vote
accepted
You can check the status code of mount, and most well written executables, with the shell special parameter ?.
From man bash:
? Expands to the exit status of the most recently executed foreground pipeline.
After you run the mount command, immediately executing echo $? will print the status code from the previous command.
# mount /dev/dvd1 /mnt
mount: no medium found on /dev/sr0
# echo $?
32
Not all executables have well defined status codes. At a minimum, it should exit with a success (0) or failure (1) code, but that's not always the case.
To expand on (and correct) your example script, I added a nested if construct for clarity. It's not the only way to test the status code and perform an action, but it's the easiest to read when learning.
#!/bin/bash
mount="/myfilesystem"
if grep -qs "$mount" /proc/mounts; then
echo "It's mounted."
else
echo "It's not mounted."
mount "$mount"
if [ $? -eq 0 ]; then
echo "Mount success!"
else
echo "Something went wrong with the mount..."
fi
fi
For more information on "Exit and Exit Status", you can refer to the Advanced Bash-Scripting Guide.
You can check the status code of mount, and most well written executables, with the shell special parameter ?.
From man bash:
? Expands to the exit status of the most recently executed foreground pipeline.
After you run the mount command, immediately executing echo $? will print the status code from the previous command.
# mount /dev/dvd1 /mnt
mount: no medium found on /dev/sr0
# echo $?
32
Not all executables have well defined status codes. At a minimum, it should exit with a success (0) or failure (1) code, but that's not always the case.
To expand on (and correct) your example script, I added a nested if construct for clarity. It's not the only way to test the status code and perform an action, but it's the easiest to read when learning.
#!/bin/bash
mount="/myfilesystem"
if grep -qs "$mount" /proc/mounts; then
echo "It's mounted."
else
echo "It's not mounted."
mount "$mount"
if [ $? -eq 0 ]; then
echo "Mount success!"
else
echo "Something went wrong with the mount..."
fi
fi
For more information on "Exit and Exit Status", you can refer to the Advanced Bash-Scripting Guide.
edited May 17 '12 at 20:15
Chris Down
78.4k13187200
78.4k13187200
answered May 17 '12 at 16:15
George M
8,99623247
8,99623247
1
There's no need to export$MOUNT. This script will also break if the filesystem has any character that would undergo wordsplitting (spaces, etc.). You should always quote your expansions.
– Chris Down
May 17 '12 at 18:49
@ChrisDown You're right. I only deleted the obvious dangling ';then'. In the future, feel free to edit my answer to make it more correct.
– George M
May 17 '12 at 19:30
Er... this will still break. You have still not quoted the expansions. On your advice, I'll do it now.
– Chris Down
May 17 '12 at 20:14
I also wouldn't recommend linking to the infamous "Advanced" Bash scripting guide, it's full of errors and will teach people to write bugs, not scripts. BashGuide is a far better alternative.
– Chris Down
May 17 '12 at 20:15
2
@ChrisDown "Word splitting will eat your babies if you don't quote things properly." Words to live by.
– George M
May 17 '12 at 21:25
add a comment |
1
There's no need to export$MOUNT. This script will also break if the filesystem has any character that would undergo wordsplitting (spaces, etc.). You should always quote your expansions.
– Chris Down
May 17 '12 at 18:49
@ChrisDown You're right. I only deleted the obvious dangling ';then'. In the future, feel free to edit my answer to make it more correct.
– George M
May 17 '12 at 19:30
Er... this will still break. You have still not quoted the expansions. On your advice, I'll do it now.
– Chris Down
May 17 '12 at 20:14
I also wouldn't recommend linking to the infamous "Advanced" Bash scripting guide, it's full of errors and will teach people to write bugs, not scripts. BashGuide is a far better alternative.
– Chris Down
May 17 '12 at 20:15
2
@ChrisDown "Word splitting will eat your babies if you don't quote things properly." Words to live by.
– George M
May 17 '12 at 21:25
1
1
There's no need to export
$MOUNT. This script will also break if the filesystem has any character that would undergo wordsplitting (spaces, etc.). You should always quote your expansions.– Chris Down
May 17 '12 at 18:49
There's no need to export
$MOUNT. This script will also break if the filesystem has any character that would undergo wordsplitting (spaces, etc.). You should always quote your expansions.– Chris Down
May 17 '12 at 18:49
@ChrisDown You're right. I only deleted the obvious dangling ';then'. In the future, feel free to edit my answer to make it more correct.
– George M
May 17 '12 at 19:30
@ChrisDown You're right. I only deleted the obvious dangling ';then'. In the future, feel free to edit my answer to make it more correct.
– George M
May 17 '12 at 19:30
Er... this will still break. You have still not quoted the expansions. On your advice, I'll do it now.
– Chris Down
May 17 '12 at 20:14
Er... this will still break. You have still not quoted the expansions. On your advice, I'll do it now.
– Chris Down
May 17 '12 at 20:14
I also wouldn't recommend linking to the infamous "Advanced" Bash scripting guide, it's full of errors and will teach people to write bugs, not scripts. BashGuide is a far better alternative.
– Chris Down
May 17 '12 at 20:15
I also wouldn't recommend linking to the infamous "Advanced" Bash scripting guide, it's full of errors and will teach people to write bugs, not scripts. BashGuide is a far better alternative.
– Chris Down
May 17 '12 at 20:15
2
2
@ChrisDown "Word splitting will eat your babies if you don't quote things properly." Words to live by.
– George M
May 17 '12 at 21:25
@ChrisDown "Word splitting will eat your babies if you don't quote things properly." Words to live by.
– George M
May 17 '12 at 21:25
add a comment |
up vote
29
down vote
Many Linux distros have the mountpoint command. It can explicitly used to check if a directory is a mountpoint. Simple as this:
#!/bin/bash
if mountpoint -q "$1"; then
echo "$1 is a mountpoint"
else
echo "$1 is not a mountpoint"
fi
This approach will fail if you try to check an encfs, since you will stumble into a permission denied error, when run by a non-root user.
– Denys S.
Dec 1 '15 at 8:40
My solution works with encfs.
– Theodore R. Smith
Mar 22 at 16:13
add a comment |
up vote
29
down vote
Many Linux distros have the mountpoint command. It can explicitly used to check if a directory is a mountpoint. Simple as this:
#!/bin/bash
if mountpoint -q "$1"; then
echo "$1 is a mountpoint"
else
echo "$1 is not a mountpoint"
fi
This approach will fail if you try to check an encfs, since you will stumble into a permission denied error, when run by a non-root user.
– Denys S.
Dec 1 '15 at 8:40
My solution works with encfs.
– Theodore R. Smith
Mar 22 at 16:13
add a comment |
up vote
29
down vote
up vote
29
down vote
Many Linux distros have the mountpoint command. It can explicitly used to check if a directory is a mountpoint. Simple as this:
#!/bin/bash
if mountpoint -q "$1"; then
echo "$1 is a mountpoint"
else
echo "$1 is not a mountpoint"
fi
Many Linux distros have the mountpoint command. It can explicitly used to check if a directory is a mountpoint. Simple as this:
#!/bin/bash
if mountpoint -q "$1"; then
echo "$1 is a mountpoint"
else
echo "$1 is not a mountpoint"
fi
edited May 21 '12 at 18:02
George M
8,99623247
8,99623247
answered May 21 '12 at 17:50
grosshat
391124
391124
This approach will fail if you try to check an encfs, since you will stumble into a permission denied error, when run by a non-root user.
– Denys S.
Dec 1 '15 at 8:40
My solution works with encfs.
– Theodore R. Smith
Mar 22 at 16:13
add a comment |
This approach will fail if you try to check an encfs, since you will stumble into a permission denied error, when run by a non-root user.
– Denys S.
Dec 1 '15 at 8:40
My solution works with encfs.
– Theodore R. Smith
Mar 22 at 16:13
This approach will fail if you try to check an encfs, since you will stumble into a permission denied error, when run by a non-root user.
– Denys S.
Dec 1 '15 at 8:40
This approach will fail if you try to check an encfs, since you will stumble into a permission denied error, when run by a non-root user.
– Denys S.
Dec 1 '15 at 8:40
My solution works with encfs.
– Theodore R. Smith
Mar 22 at 16:13
My solution works with encfs.
– Theodore R. Smith
Mar 22 at 16:13
add a comment |
up vote
2
down vote
The easiest way which doesn't require root is:
if $(df | grep -q /mnt/ramdisk); then
fi
or to see if it isn't mounted:
if ! $(df | grep -q /mnt/ramdisk); then
fi
themountcommand doesn't need root access,dfis focused on disc space not on mount points...
– Philippe Gachoud
Nov 28 at 11:04
add a comment |
up vote
2
down vote
The easiest way which doesn't require root is:
if $(df | grep -q /mnt/ramdisk); then
fi
or to see if it isn't mounted:
if ! $(df | grep -q /mnt/ramdisk); then
fi
themountcommand doesn't need root access,dfis focused on disc space not on mount points...
– Philippe Gachoud
Nov 28 at 11:04
add a comment |
up vote
2
down vote
up vote
2
down vote
The easiest way which doesn't require root is:
if $(df | grep -q /mnt/ramdisk); then
fi
or to see if it isn't mounted:
if ! $(df | grep -q /mnt/ramdisk); then
fi
The easiest way which doesn't require root is:
if $(df | grep -q /mnt/ramdisk); then
fi
or to see if it isn't mounted:
if ! $(df | grep -q /mnt/ramdisk); then
fi
answered Mar 9 at 15:08
Theodore R. Smith
1781110
1781110
themountcommand doesn't need root access,dfis focused on disc space not on mount points...
– Philippe Gachoud
Nov 28 at 11:04
add a comment |
themountcommand doesn't need root access,dfis focused on disc space not on mount points...
– Philippe Gachoud
Nov 28 at 11:04
the
mount command doesn't need root access, df is focused on disc space not on mount points...– Philippe Gachoud
Nov 28 at 11:04
the
mount command doesn't need root access, df is focused on disc space not on mount points...– Philippe Gachoud
Nov 28 at 11:04
add a comment |
up vote
1
down vote
One more way:
if [ "$(findmnt $mount_point)" ] ; then
#Do something for positive result (exit 0)
else
#Do something for negative result (exit 1)
fi
Remove those "$()", otherwise you're not testing for exit status, you're testing the output offindmnt(which happens to output something in the true-case and nothing in the false-case, but it's not obviously safe to rely on this behaviour).
– YoungFrog
Nov 2 at 22:36
add a comment |
up vote
1
down vote
One more way:
if [ "$(findmnt $mount_point)" ] ; then
#Do something for positive result (exit 0)
else
#Do something for negative result (exit 1)
fi
Remove those "$()", otherwise you're not testing for exit status, you're testing the output offindmnt(which happens to output something in the true-case and nothing in the false-case, but it's not obviously safe to rely on this behaviour).
– YoungFrog
Nov 2 at 22:36
add a comment |
up vote
1
down vote
up vote
1
down vote
One more way:
if [ "$(findmnt $mount_point)" ] ; then
#Do something for positive result (exit 0)
else
#Do something for negative result (exit 1)
fi
One more way:
if [ "$(findmnt $mount_point)" ] ; then
#Do something for positive result (exit 0)
else
#Do something for negative result (exit 1)
fi
edited May 18 at 11:07
sungtm
31
31
answered May 18 at 10:12
Sun
111
111
Remove those "$()", otherwise you're not testing for exit status, you're testing the output offindmnt(which happens to output something in the true-case and nothing in the false-case, but it's not obviously safe to rely on this behaviour).
– YoungFrog
Nov 2 at 22:36
add a comment |
Remove those "$()", otherwise you're not testing for exit status, you're testing the output offindmnt(which happens to output something in the true-case and nothing in the false-case, but it's not obviously safe to rely on this behaviour).
– YoungFrog
Nov 2 at 22:36
Remove those "$()", otherwise you're not testing for exit status, you're testing the output of
findmnt (which happens to output something in the true-case and nothing in the false-case, but it's not obviously safe to rely on this behaviour).– YoungFrog
Nov 2 at 22:36
Remove those "$()", otherwise you're not testing for exit status, you're testing the output of
findmnt (which happens to output something in the true-case and nothing in the false-case, but it's not obviously safe to rely on this behaviour).– YoungFrog
Nov 2 at 22:36
add a comment |
up vote
0
down vote
Short statements
Check if mounted:
mount|grep -q "/mnt/data" && echo "/mnt/data is mounted; I can follow my job!"
Check if not mounted:
mount|grep -q "/mnt/data" || echo "/mnt/data is not mounted I could probably mount it!"
add a comment |
up vote
0
down vote
Short statements
Check if mounted:
mount|grep -q "/mnt/data" && echo "/mnt/data is mounted; I can follow my job!"
Check if not mounted:
mount|grep -q "/mnt/data" || echo "/mnt/data is not mounted I could probably mount it!"
add a comment |
up vote
0
down vote
up vote
0
down vote
Short statements
Check if mounted:
mount|grep -q "/mnt/data" && echo "/mnt/data is mounted; I can follow my job!"
Check if not mounted:
mount|grep -q "/mnt/data" || echo "/mnt/data is not mounted I could probably mount it!"
Short statements
Check if mounted:
mount|grep -q "/mnt/data" && echo "/mnt/data is mounted; I can follow my job!"
Check if not mounted:
mount|grep -q "/mnt/data" || echo "/mnt/data is not mounted I could probably mount it!"
answered Nov 28 at 11:02
Philippe Gachoud
423310
423310
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f38870%2fhow-to-check-if-a-filesystem-is-mounted-with-a-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
You have a funny dangling
; thenin your script.– Mat
May 17 '12 at 16:18
why are we exporting the MOUNT var and also remove the ";"
– Mike Q
Nov 23 '16 at 21:38