Handling failed mount (media not connected)
Garrett Cooper
youshi10 at u.washington.edu
Mon Sep 3 22:49:32 PDT 2007
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
More information about the freebsd-questions
mailing list