From owner-freebsd-questions@FreeBSD.ORG Mon Jun 23 18:25:05 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 464BD1065677 for ; Mon, 23 Jun 2008 18:25:05 +0000 (UTC) (envelope-from rsmith@xs4all.nl) Received: from smtp-vbr9.xs4all.nl (smtp-vbr9.xs4all.nl [194.109.24.29]) by mx1.freebsd.org (Postfix) with ESMTP id E325F8FC16 for ; Mon, 23 Jun 2008 18:25:04 +0000 (UTC) (envelope-from rsmith@xs4all.nl) Received: from slackbox.xs4all.nl (slackbox.xs4all.nl [213.84.242.160]) by smtp-vbr9.xs4all.nl (8.13.8/8.13.8) with ESMTP id m5NIP2ZM015676; Mon, 23 Jun 2008 20:25:02 +0200 (CEST) (envelope-from rsmith@xs4all.nl) Received: by slackbox.xs4all.nl (Postfix, from userid 1001) id 4DDEDBA9C; Mon, 23 Jun 2008 20:24:59 +0200 (CEST) Date: Mon, 23 Jun 2008 20:24:59 +0200 From: Roland Smith To: Helge Rohde Message-ID: <20080623182459.GA15276@slackbox.xs4all.nl> References: <200806212144.09925.heroh@gmx.de> <20080621224731.GA26997@slackbox.xs4all.nl> <200806231725.58862.heroh@gmx.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="FL5UXtIhxfXey3p5" Content-Disposition: inline In-Reply-To: <200806231725.58862.heroh@gmx.de> X-GPG-Fingerprint: 1A2B 477F 9970 BA3C 2914 B7CE 1277 EFB0 C321 A725 X-GPG-Key: http://www.xs4all.nl/~rsmith/pubkey.txt X-GPG-Notice: If this message is not signed, don't assume I sent it! User-Agent: Mutt/1.5.18 (2008-05-17) X-Virus-Scanned: by XS4ALL Virus Scanner Cc: freebsd-questions@freebsd.org Subject: Re: shellscript conditional to check for external disk X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Jun 2008 18:25:05 -0000 --FL5UXtIhxfXey3p5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jun 23, 2008 at 05:25:58PM +0000, Helge Rohde wrote: > On Saturday 21 June 2008 22:47:31 Roland Smith wrote: > > On Sat, Jun 21, 2008 at 09:44:09PM +0000, Helge Rohde wrote: > > > Hello List, > > > > > > I need to write a backup script, and one of the required actions woul= d be > > > a copy of the backup to an external firewire drive. I would like to m= ake > > > 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 id= ea > > > of simply checking for /dev/da0s1d's existance, but that won't disapp= ear > > > on disconnect, so that would leave the is a possibility that although Such devices should disappear on disconnect. > > > da0 is in /dev, it might not be connected. > > > > Use glabel(8) to give the device an unique label. There is no telling > > which device /dev/da0s1d is pointing to! After labeling you can check > > for /dev//, which should be unique. Let me rephrase that. You should actually use the file system's utility to set a label. This works for UFS (newfs, tunefs), msdosfs (newfs_msdos), ISO9660 (mkisofs) and ntfs. > > Make sure to unmount the drive at the end of the backup script, or > > you'll get a kernel panic when staff pulls the plug on a mounted device. > > > > Roland >=20 > Okay, it obviosly makes sense to use glabel instead of the device node. W= ill=20 > the glabel appear/disappear depending on whether the drive is connected? Yes, just like regular device nodes. > Is it possible to have more then one physical drive with the same glabel(= As i=20 > plan to utilize two identical Firewire disks) ? You can label both drives the same. I don't know what will happen it you try to connect them both at the same time. I guess that the creation of the second label will fail. > Either way, i still need a way to check whether a drive is attached or no= t.=20 Simple. Check for the device node. > Mounting( and unmounting!) will be done from the periodic backup > scripts. > > I am not sure how devd could help me with that, besides maybe write/delet= e a=20 > zero-byte file somewhere and have the periodic script check for its=20 > existence.=20 It can't completely. It should be able to detect your labeled device and mount it somewhere. But you _have_ to unmount _before_ the device node disappears, lest you get the aforementioned panic. It's easier to have the backup script test if the labeled device node exists. Do not forget to print a message (after the script has unmounted the drive) for the operators that the backup is finished and that the device may be disconnected. =20 > Thank you all for your help, You're welcome! Roland --=20 R.F.Smith http://www.xs4all.nl/~rsmith/ [plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated] pgp: 1A2B 477F 9970 BA3C 2914 B7CE 1277 EFB0 C321 A725 (KeyID: C321A725) --FL5UXtIhxfXey3p5 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (FreeBSD) iEYEARECAAYFAkhf6nsACgkQEnfvsMMhpyU3YwCgmi65A8Ivt6f9wuwUGdYHSTBB jUAAn2GJ9OzDUuvwkwQlnMA3gQXYIZXI =PaUr -----END PGP SIGNATURE----- --FL5UXtIhxfXey3p5--