Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 Oct 2013 12:55:08 +0100
From:      Polytropon <freebsd@edvax.de>
To:        FreeBSD <freebsd-questions@freebsd.org>
Subject:   Re: Check to see if share is mounted
Message-ID:  <20131029125508.a7525980.freebsd@edvax.de>
In-Reply-To: <20131029074019.5a7a75b9@scorpio>
References:  <20131029074019.5a7a75b9@scorpio>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 29 Oct 2013 07:40:19 -0400, Jerry wrote:
> I have several Bash scripts that backup data to a Windows drive. I am
> looking for a one or two line snippet of code that I can use to
> determine if the share is all ready mounted. I tried trapping the exit
> code of the "mount_smbfs" command, but it always returns "0". Is there
> another way to get info on the share?

That's quite easy. Just query "df" and grep for the name of
the mountpoint or the CIFS name ("device field" as it appears
in /etc/fstab). Here's an example:

	if [ df | grep "/home/bob/stuff" ]; then
		... do stuff when share is mounted ...
	else
		echo "CIFS share not availble."
		exit 1
	fi

Here, /home/bob/stuff would be the mountpoint. You could
also use the CIFS name, but it's probably more work to get
that name into a correct grep search pattern. Just make sure
the result of grep is _unique_. Of course, use variables to
make the thing more configurable. :-)

Of course, you could also query the mount command itself
and grep the results. Similarly - depending on your coding
preferences -, you could also do something like this:

	mount | grep "on /home/bob/stuff (" > /dev/null 2>&1
	[ $? -eq 1 ] && exit 1
	... and here continuing with the share mounted ...

The use of "on ... (" helps to avoid false-positive results.




-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20131029125508.a7525980.freebsd>