gpt4 book ai didi

bash - 将一分钟添加到从命令输出中提取的时间

转载 作者:行者123 更新时间:2023-11-29 09:46:16 26 4
gpt4 key购买 nike

我正在编写一个脚本来检查我家中服务器的运行状况。

smartctl -t short /dev/sda | awk '/Please wait/ {print $3}'

此命令显示 SmartCTL 完成测试所需的时间。但为了确定,我想添加一个命令 sleep ,该命令的输出加上 1 分钟,以确保它真的完成了。

有人能帮帮我吗?

最佳答案

您可以捕获命令管道的输出并将其用作 sleep 的参数:

sleep_time=$(smartctl -t short /dev/sda | awk '/Please wait/ {print $3}')
# add logic to check if sleep_time is a number etc.
if [[ $sleep_time ]]; then
sleep $((sleep_time + 60)) # assuming smartctl prints the wait value in seconds
else
# there was no sleep time extracted from smartctl - add appropriate logic to handle that situation
fi

关于bash - 将一分钟添加到从命令输出中提取的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41925689/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com