1

I was trying to apply these instructions on how to automatically dim brightness when battery is low, but in the answer, this command didn't work with me

> percent_left=$((100 * `cat /sys/class/power_supply/BAT0/charge_now` / ` cat /sys/class/power_supply/BAT0/charge_full`))

It said

cat: /sys/class/power_supply/BAT0/charge_now: No such file or directory
cat: /sys/class/power_supply/BAT0/charge_full: No such file or directory
bash: 100 *  / : syntax error: operand expected (error token is "/ ")

Any solution!! I'm a beginner Ubuntu user

zyydoosh
  • 135

2 Answers2

0

Install acpi:

$ sudo apt install acpi

$ acpi 

View the battery percentage:

$ echo $(acpi | cut -f2 -d, | cut -c2- | cut -f1 -d%)%

Automatically dim brightness if battery is low:

$ A=$(acpi | cut -f2 -d, | cut -c2- | cut -f1 -d%)
$ B=15 # if low battery is <=15.
$ if [ "$A" -le "$B" ]; then xrandr --output VGA-1 --brightness .5; fi;

Here, VGA-1 is the screen. Value of brightness is 50%. (--brightness .5)

I need your feedback ;)

0

I have the same problem on my system:

$ cat /sys/class/power_supply/BAT0/charge_now
cat: /sys/class/power_supply/BAT0/charge_now: No such file or directory

The reason is sometimes it is BAT0 and sometimes it is BAT1. The solution is to search for either one like this:

$ cat /sys/class/power_supply/BAT*/charge_now
6216000

The BAT* wildcard lets it find either BAT0 or BAT1.

The complete command then:

$ percent_left=$((100 * `cat /sys/class/power_supply/BAT*/charge_now` / ` cat /sys/class/power_supply/BAT*/charge_full`))

$ echo $percent_left
100