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,