BashScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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