对于我的第一个 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/