gpt4 book ai didi

linux - 每 2 秒更新一次 Bash 命令(无需每次都重新运行代码)

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:23:04 27 4
gpt4 key购买 nike

对于我的第一个 bash 项目,我正在开发一个简单的 bash 脚本来显示有关我的系统的基本信息:

#!/bash/sh
UPTIME=$(w)
MHZ=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)
TEMP=$(cat /sys/class/thermal/thermal_zone0/temp)

#UPTIME shows the uptime of the device
#MHZ shows the overclocked specs
#TEMP shows the current CPU Temperature

echo "$UPTIME" #displays uptime
echo "$MHZ" #displays overclocked specs
echo "$TEMP" #displays CPU Temperature

我的问题:我如何编写此代码,以便正常运行时间CPU温度2秒刷新一次而不每次都重新生成新代码(我只想更新这两个变量,而不必再次输入文件路径并重新运行整个脚本)。

此代码在我的系统上已经运行良好,但在命令行中执行后,信息不会更新,因为它执行了命令并等待下一个命令,而不是更新诸如 之类的变量UPTIME 实时。

我希望有人理解我正在努力实现的目标,对于我对这个想法的错误措辞感到抱歉。

提前致谢...

最佳答案

我想这对你有帮助。您可以使用 watch 命令每两秒更新一次,而无需循环。

watch ./filename.sh

它会每两秒为您更新一次该命令。

watch - execute a program periodically, showing output fullscreen

关于linux - 每 2 秒更新一次 Bash 命令(无需每次都重新运行代码),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29296008/

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