[kwlug-disc] Sleep until command is finished

William Park opengeometry at yahoo.ca
Thu Jan 6 15:15:40 EST 2022


1. 'smartctl' starts "short" test on the drive and exits.  No need to 
background it.
2. $PPID is parent process of your shell.  This is where you "see" hanging.

The test is run by the drive itself, so you probably want to put '-l 
selftest' in the loop, rather than outside.

--William

On 1/6/22 1:06 PM, Charles M 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
> 
> _______________________________________________
> kwlug-disc mailing list
> kwlug-disc at kwlug.org
> https://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org
> 




More information about the kwlug-disc mailing list