script to disable writeback when a drive is idle

From
<hidden>
Date
2021-01-06 17:50:20
Hi all,

I have two stacks of a HDD with a bcache SSD in front of it in writeback mode. I have made the following quick and dirty script to disable writeback when the HDD is in standby. I hope it helps somebody:

# cat writeback.sh
#!/bin/bash

function sdbGetState()
{
        hdparmstr=$(hdparm -C /dev/sdb | grep drive)
    echo $hdparmstr
}

function sddGetState()
{
        hdparmstr=$(hdparm -C /dev/sdd | grep drive)
        echo $hdparmstr
}

strSdb=$(sdbGetState)
echo $strSdb

strSdd=$(sddGetState)
echo $strSdd


if [ "$strSdd" = 'drive state is: active/idle' ];
then
    echo 1 > /sys/block/bcache0/bcache/writeback_running
    echo active
else
    echo 0 > /sys/block/bcache0/bcache/writeback_running
    echo idle
fi

if [ "$strSdb" = 'drive state is: active/idle' ];
then
        echo 1 > /sys/block/bcache1/bcache/writeback_running
        echo active
else
        echo 0 > /sys/block/bcache1/bcache/writeback_running
        echo idle
fi

---

Take your mailboxes with you. Free, fast and secure Mail &amp; Cloud: https://www.eclipso.eu - Time to change!

Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help