Blog Code Forum

ArchLinux:Shell

From Wiki.cyring.fr

Revision as of 15:58, 30 April 2012 by Cyril (Talk | contribs)
Jump to: navigation, search
Bash script to read ASUS sensors


Sensors.png

$ nano ~/.bashrc

  1. function chipset ()
  2. {
  3.   local hwpath="/sys/class/hwmon/hwmon2"
  4.  
  5.   local Dev="all"
  6.   case "${1}" in
  7.     ( fan | FAN )
  8.       Label1="min"
  9.       Label2="max"
  10.       Dev="fan" ;;
  11.     ( temp | temperature | TEMP | TEMPERATURE )
  12.       Label1="max"
  13.       Label2="crit"
  14.       Dev="temp" ;;
  15.     ( volt | voltage | VOLT | VOLTAGE )
  16.       Label1="min"
  17.       Label2="max"
  18.       Dev="in" ;;
  19.     ( * )
  20.       echo "Usage: $FUNCNAME [FAN] [TEMP] [VOLT]"
  21.       return 1 ;;
  22.   esac
  23.  
  24.   declare -i I=1
  25.   while [ -e ${hwpath}/${Dev}${I}_label ];
  26.     do
  27.       local Label=$(cat ${hwpath}/${Dev}${I}_label)
  28.       local Input=$(cat ${hwpath}/${Dev}${I}_input)
  29.       local   Min=$(cat ${hwpath}/${Dev}${I}_${Label1})
  30.       local   Max=$(cat ${hwpath}/${Dev}${I}_${Label2})
  31.  
  32.       local Padding=""
  33.       declare -i Len=${#Label}
  34.       for (( L=${Len}; L<32; L++ ));
  35.         do
  36.           Padding=${Padding}" "
  37.         done
  38.  
  39.       echo -e "${Label}${Padding}${Input}\t[ ${Min} - ${Max} ]";
  40.  
  41.       I=I+1
  42.   done
  43. }
Personal tools