Skip to content

Instantly share code, notes, and snippets.

@Natsu-Akatsuki
Last active June 26, 2022 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Natsu-Akatsuki/a4d5650041dfb9330d570665067a5f50 to your computer and use it in GitHub Desktop.
Save Natsu-Akatsuki/a4d5650041dfb9330d570665067a5f50 to your computer and use it in GitHub Desktop.
BashScript
#!/bin/bash
adjust_fan() {
pcie_pos=$1
target_state=$2
cur_state=$(sudo racadm get "System.PCIESlotLFM.${pcie_pos}" | grep LFMMode | cut -c 9-)
if [ "$target_state" != "$cur_state" ]; then
sudo racadm set System.PCIESlotLFM."${pcie_pos}".LFMMode "${target_state}"
echo "风扇调整为:${target_state}模式(Custom: off Automatic: on)"
fi
}
while true; do
# 提取温度信息:截取含"Default"的行;提取第三个字段的信息;提取前两个字符
gpu_temp=$(nvidia-smi | grep Default | awk '{print $3}' | cut -c 1-2)
max_temp=0
# 提取温度的最大值
for temp in ${gpu_temp}; do
if ((temp > max_temp)); then
max_temp="$temp"
fi
done
echo "最大的显卡温度为: ${max_temp}°C."
if [ "${max_temp}" -lt 65 ]; then
adjust_fan 3 Custom
adjust_fan 6 Custom
adjust_fan 8 Custom
else
adjust_fan 3 Automatic
adjust_fan 6 Automatic
adjust_fan 8 Automatic
fi
sleep 60
done
[Unit]
Description=a script for adjusting fans of Nvidia card
[Service]
Type=simple
ExecStart=/usr/local/bin/auto_adjust_fan
[Install]
WantedBy=multi-user.target
#!/bin/bash
# IsRoot
A=$(whoami)
if [ "$A" != 'root' ]; then
echo "You have to be root to run this script"
echo "Fail !!!"
exit 1
fi
# IdentifyArch
B=$(arch)
if [ $B == 'x86_64' ]; then
...
elif [ $B == 'aarch64' ]; then
...
elif [[ ${B:2} == '86' ]]; then
...
else
...
fi
# show code name of this distribution
release_code="$(lsb_release -cs)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment