Post by RobHI haven't really noticed this before as I don't reboot my desktop very
often, and it was a while since I last did it.
When I checked my shared NAS folders on my desktop after a recent
restart, due to the electric being switched off, I saw that none of my
media files were mounted.
sudo mount -a
and then the folders appeared.
Out of curiosity I tried 2 other ubuntu 18.04 machines, and it was
exactly the same thing, no automount.
I then googled this problem, but all I could find was how to mount a NAS
folder and how to edit the fstab file.
There has been a round of updates recently, and I wondered if it was
anything to do with that, as the NAS folders used to automount, but not
recently
It can all be a matter of timing. If you desktop boots and brings up
your network before you NAS then the share will not be available. What
happen next depends on what options you used for your share in fstab. If
memory serves me you are using smb and not nfs. With nfs I use the
_netdev option but for smb shares what I did was create a shell script
that checked if the share was mounted, if not then try mounting it. I
ran it on a cronjob, for this one client I did it hourly.
The script was if you want to downloaded it at:
<http://www.littleworksstudio.com/temp/usenet/check-network-mount.sh>
else here it is, but be mindful of the wordwrap:
#!/bin/bash
# check-network-mount.sh
#+ Check if network share in fstab is mounted, if not try and mount it
#+ v0.2 Use parameter substitution to prevent TERM error when cron job
#+ v0.3 Add delay between mount attempts to prevent 'mount error(16):
Device or resource busy'
TITLE='Check Network Mounted Share'
VER=0.3
SELF=$([[ $0 = /* ]] && echo "$0" || echo "$PWD/${0#./}")
SCRIPT=$(basename ${SELF%.*})
# Prevent 'TERM environment variable not set.' error when run by cron
export TERM=${TERM:-linux}
# My standard exit codes
declare -ir SUCCESS=0
declare -ir E_FATAL=1
declare -ir E_NOT_ROOT=64
declare -ir E_BAD_ARGS=67
declare -ir E_NO_CONNECT=73
#====================== Subroutines ======================================#
version()
{
echo "$(basename $0) v$VER"
exit $SUCCESS
}
# $1 exit code
usage()
{
cat <<-EOM
$TITLE v$VER
Usage: $(basename $0) token [tries]|OPTION
$(basename $0) is a script that checks if a network share defined in
fstab
is currently mounted, if not tries to mount it.
token - a string identifier to locate share in fstab and mtab
e.g., RemoteServer:/remote/folder /mnt/MyShare 'RemoteServer'
or 'MyShare' would be a good choice
tries - optional number of attempts to mount share before quiting
default is 3
OPTION
-h, --help display this help and exit
-v, --version output version information and exit
EOM
exit $1
}
# $1 ERR_NO, $2 message
fatal_error()
{
echo -e "Error #$1: $2" >&2
usage $1
}
check_tries()
{
re='^[0-9]+$'
[[ $1 =~ $re ]] && TRIES=$1 || fatal_error $E_BAD_ARGS 'tries arg
MUST be an integer'
}
try_mounting()
{
i=1
while [ -z "$(mount | grep $TOKEN)" ]
do
echo "Try mounting network share $TOKEN"
mount -a
sleep 5
i=$((i+1))
(( i > $TRIES )) && fatal_error $E_NO_CONNECT "Mounting network
share $TOKEN failed"
done
echo "Mounted $TOKEN successfully"
}
clear
# Parse command line
case $# in
0) fatal_error $E_BAD_ARGS "Missing required argument";;
1) [[ $1 == '-h' || $1 == '--help' ]] && usage $SUCCESS
[[ $1 == '-v' || $1 == '--version' ]] && version
TOKEN=$1; TRIES=3
;;
2) TOKEN=$1; check_tries $2
;;
*) fatal_error $E_BAD_ARGS "Invalid number of arguments";;
esac
# Need to be root for this script to work
[ "$(id -u)" == "0" ] || fatal_error $E_NOT_ROOT "Must be root to run
script use:\nsudo $0\n"
# 1st make sure token finds share defined in fstab
grep $TOKEN /etc/fstab > /dev/null || fatal_error $E_BAD_ARGS "Network
share not found in /etc/fstab matching token: $TOKEN"
# 2nd see if share is mounted else try remounting
[ -n "$(mount | grep $TOKEN)" ] && echo "Network share $TOKEN is
currently mounted" || try_mounting
--
Take care,
Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com