shellscript conditional to check for external disk

Chuck Robey chuckr at
Sat Jun 21 22:27:44 UTC 2008

Hash: SHA1

Helge Rohde wrote:
> 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?

I'm not certain this will do what you want with enough security, but if you put
the commands in to mount the dist into /etc/fstab, then later on your ask simply
"mount <diskname>", mount will follow those rules to mount the disk, if it's
indeed in existence.  Putting that into a script is pretty simple.  There are a
huge number of backup commands ... I rather like tar, which can be made to
automatically compress the output, or to ask for a single file out of the whole
archive, on restoral.  Either way, not hard to automate.

Does this fit what you wanted?  There's a good man page on fstab, and y9ou
shouold read the pages on mount and tar.

> Helge
> _______________________________________________
> freebsd-questions at mailing list
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at"

Version: GnuPG v2.0.4 (FreeBSD)
Comment: Using GnuPG with Mozilla -


More information about the freebsd-questions mailing list