且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用正则表达式提取和处理 GPU 温度信息

更新时间:2022-11-12 08:44:46

您已经将所需的温度存储在一个数组中,然后您可以用它们进行数学计算.

There you have desired temperatures stored in an array, you can then do the math with them.

arr=( $( IFS=$'\n' gawk 'BEGIN{ RS="\n\n"} { if($0 ~/amdgpu/) print $0 }' test.txt | gawk 'BEGIN{ FS="[+.]" } { if($1 ~/temp1:/) 打印 $2 }' ) )回声${arr[*]}"50 47 52 51 53

test.txt 包含您的示例输出.从传感器命令获取输入(未测试)

test.txt contains your sample output. Getting input from sensors command (not tested)

arr=( $(sensors | IFS=$'\n' gawk 'BEGIN{ RS="\n\n"} { if($0 ~/amdgpu/) print $0 }' | gawk 'BEGIN{ FS="[+.]" } { if($1 ~/temp1:/) 打印 $2 }' ) )回声${arr[*]}"50 47 52 51 53