[kwlug-disc] Sleep until command is finished
John Sellens
jsellens at syonex.com
Thu Jan 6 14:14:05 EST 2022
Doesn't
smartctl -t short
start the test on the disk and then exit, leaving the disk working on
the test, expecting you to come back later to see the results?
So there is no linux command left running to wait for it to finish.
I'm not aware of a smartctl option that says "wait for the test to
finish" - potentially the --captive option might, but heed the warning.
But if smartctl did wait to finish, why would you background the command
and then wait for it to finish? Why not just run it in the foreground?
And, as others have observed, in this script $PPID is not the pid of
the sudo or smartctl commands - it's the parent of the bash running
the script.
To accomplish your goal, I suspect you have to run smartctl to query
the test's progress e.g. something like this:
while true ; do
smartctl -a /dev/sda | grep -q 'Self-test routing in progress'
if [ $? -ne 0 ]; then
echo test finished
break
fi
done
Hope that helps
John
On Thu, 2022/01/06 01:06:13PM -0500, Charles M <chaslinux at gmail.com> wrote:
| My bash-foo is very rusty. I'm trying to run smartmontools to check a
| drive using the short test option (which usually takes less than 2
| minutes to complete). After the command is finished I want to then
| probe for the results of the test. Here's my script:
|
| #!/bin/bash
| sudo smartctl -t short /dev/sda &
| while ps -p $PPID > /dev/null; do sleep 1; done;
| sudo smartctl -l selftest /dev/sda | grep "# 1"
|
| This seems to hang after smartctl starts the short test. I've waited
| well after the time smartctl should finish and it doesn't seem to
| finish and run the second smartctl command.
|
| Thanks,
|
| Charles
More information about the kwlug-disc
mailing list