From owner-freebsd-questions@FreeBSD.ORG Fri Apr 14 21:40:48 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0B2BC16A401 for ; Fri, 14 Apr 2006 21:40:48 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from mxout1.cac.washington.edu (mxout1.cac.washington.edu [140.142.32.134]) by mx1.FreeBSD.org (Postfix) with ESMTP id 62FD743D48 for ; Fri, 14 Apr 2006 21:40:47 +0000 (GMT) (envelope-from youshi10@u.washington.edu) Received: from smtp.washington.edu (smtp.washington.edu [140.142.32.139]) by mxout1.cac.washington.edu (8.13.6+UW06.03/8.13.5+UW06.03) with ESMTP id k3ELekNB016561 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 14 Apr 2006 14:40:46 -0700 X-Auth-Received: from [128.208.7.243] (pinocchio.dyn.cs.washington.edu [128.208.7.243]) (authenticated authid=youshi10) by smtp.washington.edu (8.13.6+UW06.03/8.13.6+UW06.03) with ESMTP id k3ELekR3004315 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Fri, 14 Apr 2006 14:40:46 -0700 Mime-Version: 1.0 (Apple Message framework v749.3) In-Reply-To: <20060414131931.Q81702@home.ephemeron.org> References: <443F5CE6.4080107@u.washington.edu> <20060414091338.GY44921@wantadilla.lemis.com> <443FF97B.6000303@u.washington.edu> <20060414130832.Y81702@home.ephemeron.org> <20060414131931.Q81702@home.ephemeron.org> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <308097D9-B881-4A41-89F2-B3D963C17EA4@u.washington.edu> Content-Transfer-Encoding: 7bit From: Garrett Cooper Date: Fri, 14 Apr 2006 14:43:01 -0700 To: FreeBSD Questions X-Mailer: Apple Mail (2.749.3) X-Uwash-Spam: Gauge=IIIIIII, Probability=7%, Report='__CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0, __STOCK_PHRASE_7 0' Subject: Re: Determining whether or not a SCSI disk is in use 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: Fri, 14 Apr 2006 21:40:48 -0000 On Apr 14, 2006, at 1:21 PM, Bigby Findrake wrote: > On Fri, 14 Apr 2006, Bigby Findrake wrote: > > I'm sorry, I'm an idiot - the script, in its current incarnation, > needs to be modified. It's doing exactly what you don't want it to > do - it will shut down the disk if there was activity. The if > statement should read: > > if [ $STATUS -ne 0 ] > >> On Fri, 14 Apr 2006, Garrett Cooper wrote: >> >>> Yes. Recently accessed or is being accessed. >>> -Garrett >> >> Well, for a shell-script-hack, which (i) requires no new kernel >> and (ii) could be fairly portable but (iii) could conceivably miss >> some activity, you could do something like the following: >> >> #!/bin/sh >> >> DISKDEV=da0 >> SHUTDOWN_COMMAND="camcontrol stop 0,1,0" >> SECONDS=60 >> >> # check for activity >> # watch iostat for $SECONDS seconds for anything >> >> iostat -d $DISKDEV 1 5 | awk ' NR>2 && $2>0 { print "x" } ' |\ >> grep x > /dev/null >> >> STATUS=$? >> >> if [ $STATUS -eq 0 ] >> then >> >> # there was activity, >> $SHUTDOWN_COMMAND >> fi Brilliant! That's exactly what I was looking for! The only thing I've noticed is that there is a small amount of data being transferred while the disk is idle, so perhaps the sampling needs to watch for the amount of data as well as the overall transactions being done to properly fix up a script to do this? Anyhow, I'll end up doing that, but thanks for the command :). -Garrett