From owner-freebsd-questions@FreeBSD.ORG Tue Oct 29 11:55:25 2013 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 5414F13C for ; Tue, 29 Oct 2013 11:55:25 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de (mx01.qsc.de [213.148.129.14]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 18A9C2FF0 for ; Tue, 29 Oct 2013 11:55:24 +0000 (UTC) Received: from r56.edvax.de (port-92-195-117-74.dynamic.qsc.de [92.195.117.74]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx01.qsc.de (Postfix) with ESMTPS id 44E433C3A2 for ; Tue, 29 Oct 2013 12:55:17 +0100 (CET) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id r9TBt80X005207 for ; Tue, 29 Oct 2013 12:55:08 +0100 (CET) (envelope-from freebsd@edvax.de) Date: Tue, 29 Oct 2013 12:55:08 +0100 From: Polytropon To: FreeBSD 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> Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Oct 2013 11:55:25 -0000 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, ...