Handling failed mount (media not connected)

L Goodwin xrayv19 at yahoo.com
Tue Sep 4 18:15:40 PDT 2007


--- Garrett Cooper <youshi10 at u.washington.edu> wrote:

> 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.

Thanks, Garrett. I was wondering about the "[]" vs.
"{}" (every code example I've seen uses the square
brackets). It's been 10 years since I did any serious
shell scripting.

I finally installed the MAN and INFO pages on the
server I'm working on yesterday -- much faster than
accessing them online!
I'd like to see all MAN pages show return values and
where any output goes, and more examples that cover
each combination of the former in a real-world
scenario. If *NIX/BSD is going to take on Windows,
they need to be better in every significant way (which
includes better documentation for those who are not
already experts).



      ____________________________________________________________________________________
Park yourself in front of a world of choices in alternative vehicles. Visit the Yahoo! Auto Green Center.
http://autos.yahoo.com/green_center/ 


More information about the freebsd-questions mailing list