I am trying to write a script for my Ubuntu system to hibernate, whenever the amount of battery left is (say) 5%. This script will run on startup.
I can get the battery left using
upower -d |grep perc
Then I wish to use
sudo pm-hibernate
whenever battery reaches <= 5%. But this requires superuser permission. AND I DON'T WANT TO TYPE PASSWORD AGAIN AND AGAIN AFTER EVERY LOGIN.
One way is to use add the following line in /etc/sudoers
yourlogin ALL=(ALL) NOPASSWD: command_here
But most people recommend against that.
Another way is to add a custom startup script in /etc/init.d
. But I am not sure whether it is a safe choice.
Also, is there any other alternative which would be best for my purpose?