From owner-freebsd-questions@FreeBSD.ORG Tue Sep 4 05:49:32 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AE71816A421 for ; Tue, 4 Sep 2007 05:49:32 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from mxout7.cac.washington.edu (mxout7.cac.washington.edu [140.142.32.178]) by mx1.freebsd.org (Postfix) with ESMTP id 7C89A13C45D for ; Tue, 4 Sep 2007 05:49:32 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from smtp.washington.edu (smtp.washington.edu [140.142.33.7] (may be forged)) by mxout7.cac.washington.edu (8.13.7+UW06.06/8.13.7+UW07.06) with ESMTP id l845nVDD032543 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 3 Sep 2007 22:49:31 -0700 X-Auth-Received: from [192.168.10.45] (c-24-10-12-194.hsd1.ca.comcast.net [24.10.12.194]) (authenticated authid=youshi10) by smtp.washington.edu (8.13.7+UW06.06/8.13.7+UW07.03) with ESMTP id l845nU6x008668 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 3 Sep 2007 22:49:31 -0700 Message-ID: <46DCF1EA.500@u.washington.edu> Date: Mon, 03 Sep 2007 22:49:30 -0700 From: Garrett Cooper User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: Robert Huff References: <813384.83992.qm@web58102.mail.re3.yahoo.com> <18140.54529.1923.789795@jerusalem.litteratus.org> In-Reply-To: <18140.54529.1923.789795@jerusalem.litteratus.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-PMX-Version: 5.3.3.310218, Antispam-Engine: 2.5.1.298604, Antispam-Data: 2007.9.3.222523 X-Uwash-Spam: Gauge=IIIIIII, Probability=7%, Report='__CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0, __STOCK_PHRASE_7 0, __USER_AGENT 0' Cc: freebsd-questions@freebsd.org Subject: Re: Handling failed mount (media not connected) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Sep 2007 05:49:32 -0000 Robert Huff wrote: > L Goodwin writes: > > >> My backup script (sh) works fine except when the >> backup drive (USB Flash drive) is not plugged in. I'm >> using mount_msdosfs to mount the backup drive. >> >> What is the best way to handle mount_msdosfs error? >> If the drive is not mounted, I want to detect the >> failure and execute error-handling code. >> > > First approximation, using sh: > > ls /dev | grep da4s1 > if [ $? -eq 0 ]; > then > # drive is available > > else > # drive is not available > > if > > (Replace "da4s1" with whatever the flash drive gets created > as.) > > > Robert Huff > Possibly better (using sh again..): #!/bin/sh error_handling_func() { err_code=$1; shift; # do something here... exit $err_code; } # This assumes that you have: # 1. cam/pass support built into the kernel. # 2. your USB device is interpreted as a SCSI device (which should be the case). # 3. your USB device is unique / identifiable by a string. camcontrol | grep 'Device string' || error_handling_func $? # do something here since it passed.. Also, FWIW conditionals are actually done like: if {statement} ; then elif {statement}; then else fi in Bourne shells. Also, mount_msdosfs should return a non-zero exit code. Cheers, -Garrett