Ecco un semplice script che, se eseguito da terminale, permette di ottenere informazioni su ogni batteria presente nel vostro computer portatile.
- create un file (es: /usr/local/bin/battery.sh)
- al suo interno inserite quanto segue
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354#!/bin/shoDIR=$( pwd )oIFS=$IFSIFS=$'\n'for BATTERY in $( find /sys -name "BAT*" -type d 2>/dev/null );docd $BATTERYPRESENT=$( grep 1 present 2>/dev/null)if [ "$PRESENT" != "" ]; thenPRESENT="Yes"elsePRESENT="No"fiMODEL="$(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 ""doneIFS=$oIFScd $oDIR - salvate il file
- date al file i permessi di esecuzione (es: chmod +x /usr/local/bin/battery.sh)
- usate lo script (eseguente da terminale: /usr/local/bin/battery.sh)