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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#!/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 |
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)