How to make umount wait, until a device is not busy?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I have a bash script file where I execute a bunch of commands.
#!/bin/bash
umount /media/hdd1
umount /media/hdd2
something1
something2
But since the comands later in the file work with the umounted HDD, I need to make sure the umount is successful before continuing.
I can of course check if the umount failed and just exit 1, but that is not ideal.
So basically, what I would like to do, is somehow make the umount command wait, until the device is not busy and then umount the HDD and continue executing the script.
It would thus work like this:
#!/bin/bash
umount /media/hdd1 # Device umounted without any problems continuing the script..
umount /media/hdd2 # Device is busy! Let's just sit around and wait until it isn't... let's say 5 minutes later whatever was accessing that HDD isn't anymore and the umount umounts the HDD and the script continues
something1
something2
Thank you.
bash mount umount
add a comment |Â
up vote
2
down vote
favorite
I have a bash script file where I execute a bunch of commands.
#!/bin/bash
umount /media/hdd1
umount /media/hdd2
something1
something2
But since the comands later in the file work with the umounted HDD, I need to make sure the umount is successful before continuing.
I can of course check if the umount failed and just exit 1, but that is not ideal.
So basically, what I would like to do, is somehow make the umount command wait, until the device is not busy and then umount the HDD and continue executing the script.
It would thus work like this:
#!/bin/bash
umount /media/hdd1 # Device umounted without any problems continuing the script..
umount /media/hdd2 # Device is busy! Let's just sit around and wait until it isn't... let's say 5 minutes later whatever was accessing that HDD isn't anymore and the umount umounts the HDD and the script continues
something1
something2
Thank you.
bash mount umount
Maybe the-l
(ell) switch? See linux.die.net/man/8/umount
– PerlDuck
3 hours ago
I don't think the lazy umount option blocks the script from executing until it finishes
– Askerman
3 hours ago
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have a bash script file where I execute a bunch of commands.
#!/bin/bash
umount /media/hdd1
umount /media/hdd2
something1
something2
But since the comands later in the file work with the umounted HDD, I need to make sure the umount is successful before continuing.
I can of course check if the umount failed and just exit 1, but that is not ideal.
So basically, what I would like to do, is somehow make the umount command wait, until the device is not busy and then umount the HDD and continue executing the script.
It would thus work like this:
#!/bin/bash
umount /media/hdd1 # Device umounted without any problems continuing the script..
umount /media/hdd2 # Device is busy! Let's just sit around and wait until it isn't... let's say 5 minutes later whatever was accessing that HDD isn't anymore and the umount umounts the HDD and the script continues
something1
something2
Thank you.
bash mount umount
I have a bash script file where I execute a bunch of commands.
#!/bin/bash
umount /media/hdd1
umount /media/hdd2
something1
something2
But since the comands later in the file work with the umounted HDD, I need to make sure the umount is successful before continuing.
I can of course check if the umount failed and just exit 1, but that is not ideal.
So basically, what I would like to do, is somehow make the umount command wait, until the device is not busy and then umount the HDD and continue executing the script.
It would thus work like this:
#!/bin/bash
umount /media/hdd1 # Device umounted without any problems continuing the script..
umount /media/hdd2 # Device is busy! Let's just sit around and wait until it isn't... let's say 5 minutes later whatever was accessing that HDD isn't anymore and the umount umounts the HDD and the script continues
something1
something2
Thank you.
bash mount umount
bash mount umount
asked 3 hours ago


Askerman
366513
366513
Maybe the-l
(ell) switch? See linux.die.net/man/8/umount
– PerlDuck
3 hours ago
I don't think the lazy umount option blocks the script from executing until it finishes
– Askerman
3 hours ago
add a comment |Â
Maybe the-l
(ell) switch? See linux.die.net/man/8/umount
– PerlDuck
3 hours ago
I don't think the lazy umount option blocks the script from executing until it finishes
– Askerman
3 hours ago
Maybe the
-l
(ell) switch? See linux.die.net/man/8/umount– PerlDuck
3 hours ago
Maybe the
-l
(ell) switch? See linux.die.net/man/8/umount– PerlDuck
3 hours ago
I don't think the lazy umount option blocks the script from executing until it finishes
– Askerman
3 hours ago
I don't think the lazy umount option blocks the script from executing until it finishes
– Askerman
3 hours ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
I think the following script will do the job. It should be run with sudo
(superuser permissions).
There is a function doer
with a while
loop, that checks with mountpoint
if a device is mounted at the specified mount point, and if it is, tries to unmount it with umount
. When the logical variable busy
is false, the while
loop is finished and the script can start 'doing some things'.
#!/bin/bash
function doer()
busy=true
while $busy
do
if mountpoint -q "$1"
then
umount "$1" 2> /dev/null
if [ $? -eq 0 ]
then
busy=false # umount successful
else
echo -n '.' # output to show that the script is alive
sleep 5 # 5 seconds for testing, modify to 300 seconds later on
fi
else
busy=false # not mounted
fi
done
########################
# main
########################
doer /media/hdd1
doer /media/hdd2
echo ''
echo 'doing something1'
echo 'doing something2'
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
I think the following script will do the job. It should be run with sudo
(superuser permissions).
There is a function doer
with a while
loop, that checks with mountpoint
if a device is mounted at the specified mount point, and if it is, tries to unmount it with umount
. When the logical variable busy
is false, the while
loop is finished and the script can start 'doing some things'.
#!/bin/bash
function doer()
busy=true
while $busy
do
if mountpoint -q "$1"
then
umount "$1" 2> /dev/null
if [ $? -eq 0 ]
then
busy=false # umount successful
else
echo -n '.' # output to show that the script is alive
sleep 5 # 5 seconds for testing, modify to 300 seconds later on
fi
else
busy=false # not mounted
fi
done
########################
# main
########################
doer /media/hdd1
doer /media/hdd2
echo ''
echo 'doing something1'
echo 'doing something2'
add a comment |Â
up vote
2
down vote
I think the following script will do the job. It should be run with sudo
(superuser permissions).
There is a function doer
with a while
loop, that checks with mountpoint
if a device is mounted at the specified mount point, and if it is, tries to unmount it with umount
. When the logical variable busy
is false, the while
loop is finished and the script can start 'doing some things'.
#!/bin/bash
function doer()
busy=true
while $busy
do
if mountpoint -q "$1"
then
umount "$1" 2> /dev/null
if [ $? -eq 0 ]
then
busy=false # umount successful
else
echo -n '.' # output to show that the script is alive
sleep 5 # 5 seconds for testing, modify to 300 seconds later on
fi
else
busy=false # not mounted
fi
done
########################
# main
########################
doer /media/hdd1
doer /media/hdd2
echo ''
echo 'doing something1'
echo 'doing something2'
add a comment |Â
up vote
2
down vote
up vote
2
down vote
I think the following script will do the job. It should be run with sudo
(superuser permissions).
There is a function doer
with a while
loop, that checks with mountpoint
if a device is mounted at the specified mount point, and if it is, tries to unmount it with umount
. When the logical variable busy
is false, the while
loop is finished and the script can start 'doing some things'.
#!/bin/bash
function doer()
busy=true
while $busy
do
if mountpoint -q "$1"
then
umount "$1" 2> /dev/null
if [ $? -eq 0 ]
then
busy=false # umount successful
else
echo -n '.' # output to show that the script is alive
sleep 5 # 5 seconds for testing, modify to 300 seconds later on
fi
else
busy=false # not mounted
fi
done
########################
# main
########################
doer /media/hdd1
doer /media/hdd2
echo ''
echo 'doing something1'
echo 'doing something2'
I think the following script will do the job. It should be run with sudo
(superuser permissions).
There is a function doer
with a while
loop, that checks with mountpoint
if a device is mounted at the specified mount point, and if it is, tries to unmount it with umount
. When the logical variable busy
is false, the while
loop is finished and the script can start 'doing some things'.
#!/bin/bash
function doer()
busy=true
while $busy
do
if mountpoint -q "$1"
then
umount "$1" 2> /dev/null
if [ $? -eq 0 ]
then
busy=false # umount successful
else
echo -n '.' # output to show that the script is alive
sleep 5 # 5 seconds for testing, modify to 300 seconds later on
fi
else
busy=false # not mounted
fi
done
########################
# main
########################
doer /media/hdd1
doer /media/hdd2
echo ''
echo 'doing something1'
echo 'doing something2'
edited 11 mins ago
answered 2 hours ago


sudodus
20.7k32768
20.7k32768
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1083624%2fhow-to-make-umount-wait-until-a-device-is-not-busy%23new-answer', 'question_page');
);
Post as a guest
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
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
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
Maybe the
-l
(ell) switch? See linux.die.net/man/8/umount– PerlDuck
3 hours ago
I don't think the lazy umount option blocks the script from executing until it finishes
– Askerman
3 hours ago