This is my first post here. I am a hobbyist.
I am on an RPi4 running "Raspbian GNU/Linux 10 (buster)".
A pipeline gets the power status of a bunch of hard drives. However, on some drives hdparm becomes unresponsive.
To try to solve this I used the timeout command followed by hdparm as argument to an xargs in a pipeline, but the timeout now times-out xargs rather than hdparm.
The pipeline works fine until the last section that is the xargs command:
ls -l /dev/disk/by-uuid/ | grep -f /home/dec/drivelist| cut -d '/' -f 3 | xargs -I {} timeout -k 10 8 hdparm -C /dev/{}
( drivelist Is an ASCII file that just has a single disk UUID on each line. )
This outputs the following and times-out at sda2 where it exits and fails to continue xargs.
/dev/sdf1:
drive state is: standby
/dev/sdd1:
drive state is: standby
/dev/sdg1:
drive state is: standby
/dev/sda2:
xargs: timeout: terminated by sig
The problem here is that the timeout actually times out xargs (or the entire pipe?) rather than just hdparm.
I have tried:
ls -l /dev/disk/by-uuid/ | grep -f /home/dec/drivelist| cut -d '/' -f 3 | xargs -I {} bash -C "timeout -k 10 8 hdparm -C /dev/{}"
which does not work as desired either and outputs:
bash: timeout -k 10 8 hdparm -C /dev/sdf1: No such file or directory
bash: timeout -k 10 8 hdparm -C /dev/sdd1: No such file or directory
bash: timeout -k 10 8 hdparm -C /dev/sdg1: No such file or directory
bash: timeout -k 10 8 hdparm -C /dev/sda2: No such file or directory
How do I make this work in a pipeline, avoiding multiline code?
Thanks for your time and help.
vLAd
ADDITIONAL QUESTION RE. HDPARM
hdparm -C seems to hang checking, for example, a 2.7 TB volume. This volume is connected to the RPi via SATA-USB and plugged into a USB3 port.
Could hdparm -C on such a size perhaps need several minutes to complete and am I just impatient?
EDIT
I have added this to the pipeline, just before the xargs, but to no avail; this drops the number, so sdXn becomes just sdX.
grep -Eo "[a-z]{3}"
Instead of
bash -C "timeout -k 10 8 hdparm -C /dev/{}"
did you mean
bash -c "timeout -k 10 8 hdparm -C /dev/{}"
?
The upper- and lower-case "[Cc]" arguments to bash mean very different things...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With