Linux: get info about notebook battery

Below you can find a very simple shell script that gets information about every battery present in your notebook and shows a summary.
  1. create a new file (es: /usr/local/bin/battery.sh)
  2.  paste inside the new file the following code
    #!/bin/sh
    
    oDIR=$( pwd )
    oIFS=$IFS
    IFS=$'\n'
    
    for BATTERY in $( find /sys -name "BAT*" -type d 2>/dev/null );
    do
    	cd $BATTERY
    	
    	PRESENT=$( grep 1 present 2>/dev/null)
    	if [ "$PRESENT" != "" ]; then
    		PRESENT="Yes"
    	else
    		PRESENT="No"
    	fi
    	MODEL="$(cat manufacturer 2>/dev/null) $(cat model_name 2>/dev/null) $(cat technology 2>/dev/null)"
    	SERIAL=$(cat serial_number 2>/dev/null | sed -es/\ //g)
    	[ "$SERIAL" != "" ] && MODEL="$MODEL - s/n: $SERIAL"
    	CYCLES=$( cat cycle_count 2>/dev/null )
    	[ "$CYCLES" = "" ] && CYCLES="N.A."
    	STATUS=$( cat status 2>/dev/null )
    	[ "$STATUS" = "" ] && STATUS="N.A."
    	CAPACITY=$( cat capacity_level 2>/dev/null)
    	[ "$CAPACITY" = "" ] && CAPACITY="N.A."
    	CAPACITY_PCT=$( cat capacity 2>/dev/null)
    	[ "$CAPACITY_PCT" != "" ] && CAPACITY="${CAPACITY_PCT}% - $CAPACITY"
    	ENERGY=$( cat energy_full 2>/dev/null )
    	[ "$ENERGY" = "" ] && ENERGY="N.A."
    	ENERGY_DESIGN=$( cat energy_full_design 2>/dev/null )
    	[ "$ENERGY_DESIGN" = "" ] && ENERGY_DESIGN="N.A."
    	[[ "$ENERGY_DESIGN" != "N.A." && "$ENERGY" != "N.A." ]] && ENERGY=$(( 100*$ENERGY/$ENERGY_DESIGN ))
    	VOLTAGE=$( cat voltage_now 2>/dev/null )
    	[ "$VOLTAGE" = "" ] && VOLTAGE="N.A."
    	[ "$VOLTAGE" != "N.A." ] && VOLTAGE="$( echo $VOLTAGE | head -c2).$( echo $VOLTAGE | head -c4 | tail -c2)"
    	VOLTAGE_MIN=$( cat voltage_min_design 2>/dev/null )
    	[ "$VOLTAGE_MIN" = "" ] && VOLTAGE_MIN="N.A."
    	[ "$VOLTAGE_MIN" != "N.A." ] && VOLTAGE_MIN="$( echo $VOLTAGE_MIN | head -c2).$( echo $VOLTAGE_MIN | head -c4 | tail -c2)"
    	
    	echo "Battery $(basename $BATTERY)"
    	echo "- Model: $MODEL"
    	echo "- Present: $PRESENT"
    	echo "- Status: $STATUS"
    	echo "- Capacity: $CAPACITY"
    	[[ "$CYCLES" != "N.A." && "$CYCLES" != "0" ]] && echo "- Cycles: $CYCLES"
    	[[ "$ENERGY" != "N.A." ]] && echo "- Max Energy: ${ENERGY}% of original"
    	echo "- Voltage: $VOLTAGE (Original min: $VOLTAGE_MIN)"
    	echo ""
    	
    done
    
    
    IFS=$oIFS
    cd $oDIR
  3. save the file
  4. make the file executable (es: chmod +x /usr/local/bin/battery.sh)
  5. use the script (from a terminal  execute: /usr/local/bin/battery.sh)
   
\n' for BATTERY…">

Linux: get info about notebook battery

Below you can find a very simple shell script that gets information about every battery present in your notebook and shows a summary.
  1. create a new file (es: /usr/local/bin/battery.sh)
  2.  paste inside the new file the following code
    #!/bin/sh
    
    oDIR=$( pwd )
    oIFS=$IFS
    IFS=$'\n'
    
    for BATTERY in $( find /sys -name "BAT*" -type d 2>/dev/null );
    do
    	cd $BATTERY
    	
    	PRESENT=$( grep 1 present 2>/dev/null)
    	if [ "$PRESENT" != "" ]; then
    		PRESENT="Yes"
    	else
    		PRESENT="No"
    	fi
    	MODEL="$(cat manufacturer 2>/dev/null) $(cat model_name 2>/dev/null) $(cat technology 2>/dev/null)"
    	SERIAL=$(cat serial_number 2>/dev/null | sed -es/\ //g)
    	[ "$SERIAL" != "" ] && MODEL="$MODEL - s/n: $SERIAL"
    	CYCLES=$( cat cycle_count 2>/dev/null )
    	[ "$CYCLES" = "" ] && CYCLES="N.A."
    	STATUS=$( cat status 2>/dev/null )
    	[ "$STATUS" = "" ] && STATUS="N.A."
    	CAPACITY=$( cat capacity_level 2>/dev/null)
    	[ "$CAPACITY" = "" ] && CAPACITY="N.A."
    	CAPACITY_PCT=$( cat capacity 2>/dev/null)
    	[ "$CAPACITY_PCT" != "" ] && CAPACITY="${CAPACITY_PCT}% - $CAPACITY"
    	ENERGY=$( cat energy_full 2>/dev/null )
    	[ "$ENERGY" = "" ] && ENERGY="N.A."
    	ENERGY_DESIGN=$( cat energy_full_design 2>/dev/null )
    	[ "$ENERGY_DESIGN" = "" ] && ENERGY_DESIGN="N.A."
    	[[ "$ENERGY_DESIGN" != "N.A." && "$ENERGY" != "N.A." ]] && ENERGY=$(( 100*$ENERGY/$ENERGY_DESIGN ))
    	VOLTAGE=$( cat voltage_now 2>/dev/null )
    	[ "$VOLTAGE" = "" ] && VOLTAGE="N.A."
    	[ "$VOLTAGE" != "N.A." ] && VOLTAGE="$( echo $VOLTAGE | head -c2).$( echo $VOLTAGE | head -c4 | tail -c2)"
    	VOLTAGE_MIN=$( cat voltage_min_design 2>/dev/null )
    	[ "$VOLTAGE_MIN" = "" ] && VOLTAGE_MIN="N.A."
    	[ "$VOLTAGE_MIN" != "N.A." ] && VOLTAGE_MIN="$( echo $VOLTAGE_MIN | head -c2).$( echo $VOLTAGE_MIN | head -c4 | tail -c2)"
    	
    	echo "Battery $(basename $BATTERY)"
    	echo "- Model: $MODEL"
    	echo "- Present: $PRESENT"
    	echo "- Status: $STATUS"
    	echo "- Capacity: $CAPACITY"
    	[[ "$CYCLES" != "N.A." && "$CYCLES" != "0" ]] && echo "- Cycles: $CYCLES"
    	[[ "$ENERGY" != "N.A." ]] && echo "- Max Energy: ${ENERGY}% of original"
    	echo "- Voltage: $VOLTAGE (Original min: $VOLTAGE_MIN)"
    	echo ""
    	
    done
    
    
    IFS=$oIFS
    cd $oDIR
  3. save the file
  4. make the file executable (es: chmod +x /usr/local/bin/battery.sh)
  5. use the script (from a terminal  execute: /usr/local/bin/battery.sh)
   
\n' for BATTERY…">
\\n' for BATTERY…","author":{"@type":"Person","name":"Davide Airaghi","url":"https://www.airaghi.net/authors/davide-airaghi/"},"publisher":{"@type":"Organization","name":"Davide Airaghi"}}

Linux: get info about notebook battery

Below you can find a very simple shell script that gets information about every battery present in your notebook and shows a summary.
  1. create a new file (es: /usr/local/bin/battery.sh)
  2.  paste inside the new file the following code
    #!/bin/sh
    
    oDIR=$( pwd )
    oIFS=$IFS
    IFS=$'\n'
    
    for BATTERY in $( find /sys -name "BAT*" -type d 2>/dev/null );
    do
    	cd $BATTERY
    	
    	PRESENT=$( grep 1 present 2>/dev/null)
    	if [ "$PRESENT" != "" ]; then
    		PRESENT="Yes"
    	else
    		PRESENT="No"
    	fi
    	MODEL="$(cat manufacturer 2>/dev/null) $(cat model_name 2>/dev/null) $(cat technology 2>/dev/null)"
    	SERIAL=$(cat serial_number 2>/dev/null | sed -es/\ //g)
    	[ "$SERIAL" != "" ] && MODEL="$MODEL - s/n: $SERIAL"
    	CYCLES=$( cat cycle_count 2>/dev/null )
    	[ "$CYCLES" = "" ] && CYCLES="N.A."
    	STATUS=$( cat status 2>/dev/null )
    	[ "$STATUS" = "" ] && STATUS="N.A."
    	CAPACITY=$( cat capacity_level 2>/dev/null)
    	[ "$CAPACITY" = "" ] && CAPACITY="N.A."
    	CAPACITY_PCT=$( cat capacity 2>/dev/null)
    	[ "$CAPACITY_PCT" != "" ] && CAPACITY="${CAPACITY_PCT}% - $CAPACITY"
    	ENERGY=$( cat energy_full 2>/dev/null )
    	[ "$ENERGY" = "" ] && ENERGY="N.A."
    	ENERGY_DESIGN=$( cat energy_full_design 2>/dev/null )
    	[ "$ENERGY_DESIGN" = "" ] && ENERGY_DESIGN="N.A."
    	[[ "$ENERGY_DESIGN" != "N.A." && "$ENERGY" != "N.A." ]] && ENERGY=$(( 100*$ENERGY/$ENERGY_DESIGN ))
    	VOLTAGE=$( cat voltage_now 2>/dev/null )
    	[ "$VOLTAGE" = "" ] && VOLTAGE="N.A."
    	[ "$VOLTAGE" != "N.A." ] && VOLTAGE="$( echo $VOLTAGE | head -c2).$( echo $VOLTAGE | head -c4 | tail -c2)"
    	VOLTAGE_MIN=$( cat voltage_min_design 2>/dev/null )
    	[ "$VOLTAGE_MIN" = "" ] && VOLTAGE_MIN="N.A."
    	[ "$VOLTAGE_MIN" != "N.A." ] && VOLTAGE_MIN="$( echo $VOLTAGE_MIN | head -c2).$( echo $VOLTAGE_MIN | head -c4 | tail -c2)"
    	
    	echo "Battery $(basename $BATTERY)"
    	echo "- Model: $MODEL"
    	echo "- Present: $PRESENT"
    	echo "- Status: $STATUS"
    	echo "- Capacity: $CAPACITY"
    	[[ "$CYCLES" != "N.A." && "$CYCLES" != "0" ]] && echo "- Cycles: $CYCLES"
    	[[ "$ENERGY" != "N.A." ]] && echo "- Max Energy: ${ENERGY}% of original"
    	echo "- Voltage: $VOLTAGE (Original min: $VOLTAGE_MIN)"
    	echo ""
    	
    done
    
    
    IFS=$oIFS
    cd $oDIR
  3. save the file
  4. make the file executable (es: chmod +x /usr/local/bin/battery.sh)
  5. use the script (from a terminal  execute: /usr/local/bin/battery.sh)