[kwlug-disc] Sleep until command is finished

Alex K korobkin+kwl at gmail.com
Thu Jan 6 13:28:58 EST 2022


Isn't PPID your bash process?

Try

#!/bin/bash
sudo smartctl -t short /dev/sda &
process_id=$!
wait $process_id
sudo smartctl -l selftest /dev/sda | grep "# 1"

On Thu, Jan 6, 2022 at 1:07 PM 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
>
> _______________________________________________
> kwlug-disc mailing list
> kwlug-disc at kwlug.org
> https://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://kwlug.org/pipermail/kwlug-disc_kwlug.org/attachments/20220106/dfc7871b/attachment.htm>


More information about the kwlug-disc mailing list