Determining whether or not a SCSI disk is in use

2006-04-14 Thread Garrett Cooper

Hello again list,
   Just wondering if there was any way where I could possibly tie into 
the kernel or do something where I could determine whether or not a disk 
is currently 'in use'.
   Problem: I'm trying to spin down my disks periodically via a cronjob 
to save energy, reduce noise, and heat, and I don't want my disk to be 
spun down if it is currently in use. I do listen to music and watch 
videos for extended periods of time, so I'd rather not cause undue 
stress to the hard disks and cause the program I'm using on another 
machine to choke and die.

   Thanks!
-Garrett
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Determining whether or not a SCSI disk is in use

2006-04-14 Thread Greg 'groggy' Lehey
On Friday, 14 April 2006 at  1:27:18 -0700, Garrett Cooper wrote:
 Hello again list,
Just wondering if there was any way where I could possibly tie into
 the kernel or do something where I could determine whether or not a disk
 is currently 'in use'.
Problem: I'm trying to spin down my disks periodically via a cronjob
 to save energy, reduce noise, and heat, and I don't want my disk to be
 spun down if it is currently in use. I do listen to music and watch
 videos for extended periods of time, so I'd rather not cause undue
 stress to the hard disks and cause the program I'm using on another
 machine to choke and die.

This all depends on what you mean by in use.  Do you mean recently
accessed?

Greg
--
When replying to this message, please copy the original recipients.
If you don't, I may ignore the reply or reply to the original recipients.
For more information, see http://www.lemis.com/questions.html
See complete headers for address and phone numbers.


pgpYmfxOtkhOZ.pgp
Description: PGP signature


Re: Determining whether or not a SCSI disk is in use

2006-04-14 Thread Garrett Cooper

Greg 'groggy' Lehey wrote:


On Friday, 14 April 2006 at  1:27:18 -0700, Garrett Cooper wrote:
 


Hello again list,
  Just wondering if there was any way where I could possibly tie into
the kernel or do something where I could determine whether or not a disk
is currently 'in use'.
  Problem: I'm trying to spin down my disks periodically via a cronjob
to save energy, reduce noise, and heat, and I don't want my disk to be
spun down if it is currently in use. I do listen to music and watch
videos for extended periods of time, so I'd rather not cause undue
stress to the hard disks and cause the program I'm using on another
machine to choke and die.
   



This all depends on what you mean by in use.  Do you mean recently
accessed?

Greg
--
When replying to this message, please copy the original recipients.
If you don't, I may ignore the reply or reply to the original recipients.
For more information, see http://www.lemis.com/questions.html
See complete headers for address and phone numbers.
 


Yes. Recently accessed or is being accessed.
-Garrett
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Determining whether or not a SCSI disk is in use

2006-04-14 Thread Bigby Findrake

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 ' NR2  $20 { print x } ' |\
grep x  /dev/null

STATUS=$?

if [ $STATUS -eq 0 ]
then

# there was activity,
$SHUTDOWN_COMMAND
fi


/-/
You always miss 100% of the chances you never take.

   finger://[EMAIL PROTECTED]
  http://www.ephemeron.org/~bigby/
  irc://irc.ephemeron.org/#the_pub
news://news.ephemeron.org/alt.lemurs
/-/
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Determining whether or not a SCSI disk is in use

2006-04-14 Thread Bigby Findrake

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 ' NR2  $20 { print x } ' |\
grep x  /dev/null

STATUS=$?

if [ $STATUS -eq 0 ]
then

# there was activity,
$SHUTDOWN_COMMAND
fi




/-/
Workaholics procrastinate too... I'll sleep tommorow.

   finger://[EMAIL PROTECTED]
  http://www.ephemeron.org/~bigby/
  irc://irc.ephemeron.org/#the_pub
news://news.ephemeron.org/alt.lemurs
/-/
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Determining whether or not a SCSI disk is in use

2006-04-14 Thread Garrett Cooper

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 ' NR2  $20 { 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
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Determining whether or not a SCSI disk is in use

2006-04-14 Thread David J Brooks
On Friday 14 April 2006 16:43, Garrett Cooper wrote:
 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 ' NR2  $20 { 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 :).

Perhaps a softupdate hasn't completed yet? 

David
-- 
Sure God created the world in only six days,
but He didn't have an established user-base.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Determining whether or not a SCSI disk is in use

2006-04-14 Thread Garrett Cooper


On Apr 14, 2006, at 2:48 PM, David J Brooks wrote:


On Friday 14 April 2006 16:43, Garrett Cooper wrote:

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 ' NR2  $20 { 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 :).


Perhaps a softupdate hasn't completed yet?

David
--  
Sure God created the world in only six days,

but He didn't have an established user-base.


Hmmm... didn't think of that. Well, iostat updating did seem to be  
largely cached (only by running iostat -c did I see a change), so I'm  
not sure what the best way is of approaching this problem.
I sure wish the FreeBSD kernel team would work something out where  
the hard disk would sleep after a period of time in the kernel ACPI  
wise _.

-Garrett
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]