Date: Mon, 03 Sep 2007 22:49:30 -0700 From: Garrett Cooper <youshi10@u.washington.edu> To: Robert Huff <roberthuff@rcn.com> Cc: freebsd-questions@freebsd.org Subject: Re: Handling failed mount (media not connected) Message-ID: <46DCF1EA.500@u.washington.edu> In-Reply-To: <18140.54529.1923.789795@jerusalem.litteratus.org> References: <813384.83992.qm@web58102.mail.re3.yahoo.com> <18140.54529.1923.789795@jerusalem.litteratus.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?46DCF1EA.500>