I'm running Debian Squeeze/Testing and have this in my /etc/rc.local:
tail -f /var/log/syslog | awk '/kernel: sdb: sdb1/ {system("/bin/sleep 10; /sbin/hdparm -Y /dev/sdb")}' &
Whenever I insert a hard drive caddy I want the disc to be put into sleep mode until it's required. The drive is used only once every 24 hours to backup and the drive is changed each day.
However it doesn't work. If I remove a drive caddy and then replace it the relevant lines appear in syslog but the drive keeps spinning.
If I stop the current tail/awk processes, remove and replace the caddy then run /etc/rc.local from the command line it does work and the drive stops spinning.
I have now run out of expertise. Any suggestions please?
On 08 Nov 14:04, Barry Samuels wrote:
I'm running Debian Squeeze/Testing and have this in my /etc/rc.local:
tail -f /var/log/syslog | awk '/kernel: sdb: sdb1/ {system("/bin/sleep 10; /sbin/hdparm -Y /dev/sdb")}' &
Whenever I insert a hard drive caddy I want the disc to be put into sleep mode until it's required. The drive is used only once every 24 hours to backup and the drive is changed each day.
However it doesn't work. If I remove a drive caddy and then replace it the relevant lines appear in syslog but the drive keeps spinning.
If I stop the current tail/awk processes, remove and replace the caddy then run /etc/rc.local from the command line it does work and the drive stops spinning.
I have now run out of expertise. Any suggestions please?
(1) That process will sit and watch the old syslog *after* a rotation has happened, so after a day will never work.
(2) This looks *far* more like a job for udev rather than something watching syslog.
So, in /etc/udev/rules.d/99-local.rules (file probably doesn't exist by default, but is the usual name I give to my local rules) add:
== Begin Snippet == KERNEL=="sdb", RUN+="/usr/local/bin/sleep_sdb.sh" == End Snippet ==
Then create a file /usr/local/bin/sleep_sdb.sh containing:
== Begin File == #!/bin/sh
/bin/sleep 10 /sbin/hdparm -Y /dev/sdb == End File ==
Make the file executable (chmod +x /usr/local/bin/sleep_sdb.sh) and bob should be your mother's brother.
Cheers,
On 08 Nov 15:35, Brett Parker wrote:
On 08 Nov 14:04, Barry Samuels wrote:
I'm running Debian Squeeze/Testing and have this in my /etc/rc.local:
tail -f /var/log/syslog | awk '/kernel: sdb: sdb1/ {system("/bin/sleep 10; /sbin/hdparm -Y /dev/sdb")}' &
Whenever I insert a hard drive caddy I want the disc to be put into sleep mode until it's required. The drive is used only once every 24 hours to backup and the drive is changed each day.
However it doesn't work. If I remove a drive caddy and then replace it the relevant lines appear in syslog but the drive keeps spinning.
If I stop the current tail/awk processes, remove and replace the caddy then run /etc/rc.local from the command line it does work and the drive stops spinning.
I have now run out of expertise. Any suggestions please?
(1) That process will sit and watch the old syslog *after* a rotation has happened, so after a day will never work.
(though, if you used -F rather than -f it *should* then work...)
(2) This looks *far* more like a job for udev rather than something watching syslog.
So, in /etc/udev/rules.d/99-local.rules (file probably doesn't exist by default, but is the usual name I give to my local rules) add:
== Begin Snippet == KERNEL=="sdb", RUN+="/usr/local/bin/sleep_sdb.sh" == End Snippet ==
That might be better as:
ACTION=="add", KERNEL=="sdb", RUN+="/usr/local/bin/sleep_sdb.sh"
Then create a file /usr/local/bin/sleep_sdb.sh containing:
== Begin File == #!/bin/sh
/bin/sleep 10 /sbin/hdparm -Y /dev/sdb == End File ==
Make the file executable (chmod +x /usr/local/bin/sleep_sdb.sh) and bob should be your mother's brother.
(OK - so it's terribly bad form to follow up to myself, but hey - it's Monday :)
On Mon, 8 Nov 2010 15:44:07 +0000 Brett Parker iDunno@sommitrealweird.co.uk wrote:
(OK - so it's terribly bad form to follow up to myself, but hey - it's Monday :)
Never seems to bother Chris. :-)
Mick
On Mon, Nov 08, 2010 at 08:31:25PM +0000, mick wrote:
On Mon, 8 Nov 2010 15:44:07 +0000 Brett Parker iDunno@sommitrealweird.co.uk wrote:
(OK - so it's terribly bad form to follow up to myself, but hey - it's Monday :)
Never seems to bother Chris. :-)
Who, me? :-)
I've never really understood anyway why it's regarded as a bad thing, if you suddenly realise what the answer is or find some more informamtion about a question, why not say so?
On 08/11/10 15:35:45, Brett Parker wrote:
(2) This looks *far* more like a job for udev rather than something watching syslog.
So, in /etc/udev/rules.d/99-local.rules (file probably doesn't exist by default, but is the usual name I give to my local rules) add:
== Begin Snippet == KERNEL=="sdb", RUN+="/usr/local/bin/sleep_sdb.sh" == End Snippet ==
Then create a file /usr/local/bin/sleep_sdb.sh containing:
== Begin File == #!/bin/sh
/bin/sleep 10 /sbin/hdparm -Y /dev/sdb == End File ==
Make the file executable (chmod +x /usr/local/bin/sleep_sdb.sh) and bob should be your mother's brother.
Cheers,
Brett Parker http://www.sommitrealweird.co.uk/
I've tried the UDEV suggestion but the strange thing is that when the rule is activated and the script runs I can hear the drive switch off but it then restarts immediately. If I then run that script from a terminal the drive shuts down and doesn't restart.
What I've done in the end is to substitute "/sbin/hdparm -S 60 /dev/sdb" in the UDEV rule and the drive then switches off 5 minutes later which is fine.
I don't understand why it should restart after the hdparm -Y command but at least it's working now.
Many thanks for your suggestion.
On 10 Nov 15:25, Barry Samuels wrote:
I've tried the UDEV suggestion but the strange thing is that when the rule is activated and the script runs I can hear the drive switch off but it then restarts immediately. If I then run that script from a terminal the drive shuts down and doesn't restart.
I can now reveal why this happens (probably)... according to my debian system in /etc/udev/rules.d there is a file z60_hdparm.conf, that then applies hdparm rules... thus overriding anything previously sent at it.
What I've done in the end is to substitute "/sbin/hdparm -S 60 /dev/sdb" in the UDEV rule and the drive then switches off 5 minutes later which is fine.
You could try adding the following to /etc/hdparm.conf:
/dev/hdb { sleep spindown_time = 60 }
And remove your udev rule... that *should* do everything for you, and will get invoked by the already existing udev rule.
Thanks,
On 10/11/10 16:00:10, Brett Parker wrote:
On 10 Nov 15:25, Barry Samuels wrote:
I've tried the UDEV suggestion but the strange thing is that when the rule is activated and the script runs I can hear the drive switch off but it then restarts immediately. If I then run that script from a terminal the drive shuts down and doesn't restart.
I can now reveal why this happens (probably)... according to my debian system in /etc/udev/rules.d there is a file z60_hdparm.conf, that then applies hdparm rules... thus overriding anything previously sent at it.
What I've done in the end is to substitute "/sbin/hdparm -S 60 /dev/sdb" in the UDEV rule and the drive then switches off 5 minutes later which is fine.
You could try adding the following to /etc/hdparm.conf:
/dev/hdb { sleep spindown_time = 60 }
And remove your udev rule... that *should* do everything for you, and will get invoked by the already existing udev rule.
Thanks,
Brett Parker http://www.sommitrealweird.co.uk/
Thanks Brett but that has the same effect i.e. the drive switches off but restarts immediately.
The /sbin/hdparm -S 60 rule seems to work though so I may as well stick with that.