Skip to content

Instantly share code, notes, and snippets.

@cirrusUK
Created May 30, 2020 19:57
Show Gist options
  • Save cirrusUK/f8bd03fdc8caf9b2a204ba7ccaa210a5 to your computer and use it in GitHub Desktop.
Save cirrusUK/f8bd03fdc8caf9b2a204ba7ccaa210a5 to your computer and use it in GitHub Desktop.
shell script to control fan settings on thinkpad (x220)
#!/bin/bash
# (1) prompt user, and read command line argument
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
printf %"s\n"
printf %"s\n"
tput setaf 3
blue=`tput setaf 4`
echo -e "\e[0;36m📺 \e[0;31m📺 \e[0;32m📺 \e[0;33m📺 \e[0;34m📺 \e[0;39m📺 \e[0;38m📺 \e[0;35m📺 \e[0;37m📺 \e[0;33m📺 \e[0;39m📺 \e[0m\n"
toilet -f future --metal ' BashFan'
tput setaf 2
printf %"s\n"
printf '\E[33m'" Enter number/letter of desired\n fan control setting" | pv -qL 20 ;
echo ''
echo ''
tput setaf 4
read -p "1= (fan off)
2= (low speed)
3= Medium Speed
4= Maximum Speed
5= Automatic Default
6= Disengaged
`tput setaf 2`
Q= Exit
`tput setaf 1`
Set Fan =: " answer
tput setaf 2
echo "You entered: $answer"
tput setaf 3
# (2) handle the command line argument we were given
while true
do
case $answer in
[1]* ) echo level 0 | sudo tee /proc/acpi/ibm/fan
echo "Fan Off"
break;;
[2]* ) echo level 2 | sudo tee /proc/acpi/ibm/fan
echo "Low Speed "
break;;
[3]* ) echo level 4 | sudo tee /proc/acpi/ibm/fan
echo "Medium Speed"
break;;
[4]* ) echo level 7 | sudo tee /proc/acpi/ibm/fan
echo "Maximum Speed"
break;;
[5]* ) echo level auto | sudo tee /proc/acpi/ibm/fan
echo "Automatic Default"
break;;
[6]* ) echo level disengaged | sudo tee /proc/acpi/ibm/fan
echo "Disengaged"
break;;
[Qq]* ) exit;;
* ) echo -e '\E[18m'"Goodbye, do call again.\n"; break ;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment