I want to prevent my hard drive, an internal drive externally attached via USB dock, from spinning down. I don't see any way to adjust APM through hdparm
, so I'm assuming it's limited by the firmware of the dock. This spins up the drive:
sudo dd if=/dev/sdc of=/dev/null count=1 skip=$RANDOM
But when I put the same thing in crontab via
sudo crontab -e
and
* * * * * dd if=/dev/sdc of=/dev/null count=1 skip=$RANDOM
nothing happens. Yes, I did check whether the drive is at /dev/sdc
. I don't know if this info is relevant, but I've edited the crontab several times, and in each time, it suggested to save in a different file by default, which I followed. I'm not sure if this is the correct usage of skip=$RANDOM
to read from a random block to prevent reading from cache.
Also, how can I make sure I target the correct drive persistently across several boot-ups or other orders of plugging in other devices, rather than targeting whatever ends up being /dev/sdc
? I'm thinking something like
dd if=(findmnt -rn -S UUID=number_from_blkid -o SOURCE) of/dev/null count=1 skip=$RANDOM
but I don't know how to nest the return of the parenthetical statement into the outer statement. And even if I could, it would return /dev/sdX2
, where X
is whatever letter it happens to be and 2
is the only usable partition. The other is Windows reserved. This is less elegant than plain sdX
.
$RANDOM
is a bashism whereascron
runs jobs insh
by default - are you sure it isn't just returning empty?dd
command outside ofcrontab
, it will cause the drive to spin back up, even after the fact that I've added the same command tocrontab
. But this answer suggests it works.bash -c 'dd if=/dev/sda of=/dev/null count=1 skip=$RANDOM'
whereas yours uses the default cron shellbash -c
to the rest did the trick. Now, how can I do this byUUID
rather than/dev/sdX
? I'm basing myfindmnt
usage on this other answer and I get the UUID fromsudo blkid
.