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.
I think the following script will do the job. It should be run with
sudo
(superuser permissions).There is a function
doer
with awhile
loop, that checks withmountpoint
if a device is mounted at the specified mount point, and if it is, tries to unmount it withumount
. When the logical variablebusy
is false, thewhile
loop is finished and the script can start 'doing some things'.