1

I would like to preserve the battery on my laptop by limiting how much it gets charged.

There is a file (/sys/devices/platform/lg-laptop/battery_care_limit) with a value of 100. I can run command

echo '80' | sudo tee /sys/devices/platform/lg-laptop/battery_care_limit

I have to run this command at every reboot.

I have tried adding it via crontab -e but it doesn't work.

How do I get this command to run automatically at every reboot?

Additional information posted as an answer

thanks for the reply.

This works:

@reboot echo 80 > /home/myuser/test.txt

Tried and failed all the following:

@reboot echo 80 > /sys/devices/platform/lg-laptop/battery_care_limit
@reboot sudo echo 80 > /sys/devices/platform/lg-laptop/battery_care_limit
@reboot sleep 60 && echo 80 > /sys/devices/platform/lg-laptop/battery_care_limit
@reboot sleep 60 && sudo echo 80 > /sys/devices/platform/lg-laptop/battery_care_limit

At least the command is being attempted. journalctl -b | grep echo returns:

CRON[1041]: (myuser) CMD (sudo echo 80 > /sys/devices/platform/lg-laptop/battery_care_limit)
CRON[1045]: (myuser) CMD (sleep 60 && sudo echo 80 > /sys/devices/platform/lg-laptop/battery_care_limit)
muru
  • 207,228
elwood
  • 13

1 Answers1

1

sudo has no significance in crontab entries.

If you need to run a cron job with elevated permissions(like sudo does), then add an entry for it to the root's crontab using:

sudo crontab -e

Which runs the jobs as root instead of just:

crontab -e

Which runs the job as your user.

Raffa
  • 34,963