I found a workaround for my problem.
sudo umount -fl ${MNT}
Then it gets unmounted without any error. So there is no need anymore for the 'device is busy' dialog.
The script now looks likes this, in case someone wants to try it.
Here you go:
Code:
#!/bin/bash
## NFSMount
## Version 0.1
## Written for Debian Etch and Ubuntu Edgy Eft using Gnome.
## I don't use anything else, so I can not test anything else.
##
## Simple script which will automount shared folders on a NFS network when the remote PC
## appears to be online, and unmounts it if the remote PC appears to be offline.
## Run this script every 5 or 10 minutes with cron if you want it to be automagic -
## otherwise you have to run it yourself every time.
## Try if the script works before you run it with cron!!!
## Read the script for options before you start!
## Below are personal preferences. Change those to your situation!!!
SHARE="/home/<user>/Remote/Share" # The path to the shared folder on the remote PC
RMTIP="10.0.0.14" # The IP of the remote PC
MNT="/media/Share" # The path where you want to mount SHARE, this folder must excist before you continue, e.g.; sudo mkdir /media/Share
GRP="Unreachable" # This is in the error when a ping fails. If your ping uses another language, type 'ping -c 1 <invalid ip adres>' and see if you can get something similar unique.
## These commands will check if the other computer is online, and if the shared folder is allready mounted.
X="$(ping -c 1 ${RMTIP} | grep -c ${GRP} )"
Y="1"
Z="$(mount | grep -c ${SHARE} )"
## These commands are for the log file. You can modify them if you want to log somewhere else then your home dir.
DATE="$(date +%Y-%m-%d@%H:%M:%S)"
DIR="${HOME}/.nfsmount"
LOG="${DIR}/nfsmount.log"
## This will check if the dir for the logfiles allready excists, otherwhise it will be created.
## Comment this section if you do not want to log - also see below.
if [ ! -d "${DIR}" ]
then mkdir "${DIR}"
fi
## This is what happens if the server appears to be online.
if [ $X -lt $Y ]
then
echo "The server is online!"
if [ $Z = $Y ]
then
echo "The share is allready mounted. Will now exit."
exit
else
echo "The share is not mounted. Will now mount."
gksudo echo
sudo mount ${RMTIP}:${SHARE} ${MNT}
# Comment this section if you do not want popup dialogs.
export DEBIAN_FRONTEND=dialog
zenity --info --title="NFSMount" --text="Shared folder on ${RMTIP} has been mounted!"
# End of the section.
# Comment the line below to disable mount logs!
echo "${DATE}: ${RMTIP} is online. Shared folder on ${RMTIP} has been mounted!" >> "${LOG}"
exit
fi
fi
## This is what happens if the server appears to be offline.
if [ $X = $Y ]
then
echo "The server is offline!"
if [ $Z -lt $Y ]
then
echo "The share is allready unmounted. Will now exit."
exit
else
echo "The share is still mounted. Will now umount."
gksudo echo
sudo umount -fl ${MNT}
# Comment this section if you do not want popup dialogs.
export DEBIAN_FRONTEND=dialog
zenity --info --title="NFSMount" --text="Shared folder on ${RMTIP} has been unmounted!"
# End of the section.
# Comment the line below to disable unmount logs!
echo "${DATE}: ${RMTIP} is offline. Shared folder on ${RMTIP} has been unmounted!" >> "${LOG}"
exit
fi
fi
## End of the script.
## Goodbye.
Bookmarks