shellscript conditional to check for external disk

Camilo Reyes camiloreyes82 at yahoo.com
Sun Jun 22 16:50:35 UTC 2008


You can use /var/log/messages to check for the existence of an external
drive through a series of grep commands. Here is my log output when I
insert/remove a USB drive:

Jun 22 11:44:49 Christi kernel: umass0: <SanDisk Corporation Cruzer Mini, class
0/0, rev 2.00/0.10, addr 2> on uhub4
Jun 22 11:44:49 Christi root: Unknown USB device: vendor 0x0781 product 0x5150 b
us uhub4
Jun 22 11:44:49 Christi kernel: da0 at umass-sim0 bus 0 target 0 lun 0
Jun 22 11:44:49 Christi kernel: da0: <SanDisk Cruzer Mini 0.1> Removable Direct
Access SCSI-2 device
Jun 22 11:44:49 Christi kernel: da0: 40.000MB/s transfers
Jun 22 11:44:49 Christi kernel: da0: 122MB (250879 512 byte sectors: 64H 32S/T 1
22C)
Jun 22 11:44:49 Christi kernel: GEOM_LABEL: Label for provider da0s1 is msdosfs/
 .
Jun 22 11:44:56 Christi kernel: umass0: at uhub4 port 2 (addr 2) disconnected
Jun 22 11:44:56 Christi kernel: (da0:umass-sim0:0:0:0): lost device
Jun 22 11:44:56 Christi kernel: (da0:umass-sim0:0:0:0): removing device entry
Jun 22 11:44:56 Christi kernel: GEOM_LABEL: Label msdosfs/  removed.
Jun 22 11:44:56 Christi kernel: umass0: detached

I'm sure you can come up with creative ways to write a script that
checks for when the disk is detached.

"Bono Vince Malum"
--
-Camilo


> Date: Sat, 21 Jun 2008 21:44:09 +0000
> From: Helge Rohde <heroh at gmx.de>
> Subject: shellscript conditional to check for external disk
> To: freebsd-questions at freebsd.org
> Message-ID: <200806212144.09925.heroh at gmx.de>
> Content-Type: text/plain;  charset="us-ascii"
> 
> Hello List,
> 
> I need to write a backup script, and one of the required
> actions would be a 
> copy of the backup to an external firewire drive. I would
> like to make this 
> as easy as possible for the local staff, so i'd like to
> check whether the 
> drive is attached, if necessary mount it, copy over the
> backup  and unmount 
> it again, so that the local staff can swap the external
> disks when they're 
> not used.
>  
> Is there a canonical way to achieve what i want? I played
> with the idea of 
> simply checking for /dev/da0s1d's existance, but that
> won't disappear on 
> disconnect, so that would leave the  is a possibility that
> although da0 is 
> in /dev, it might not be connected.
> 
> Any ideas or RTFM-pointers?
> 
> Helge


      


More information about the freebsd-questions mailing list