Step one: make pm-suspend accessible to all users, no password asked
Do sudo visudo
and add this line at the end of the file: yourusername ALL=NOPASSWD: /usr/sbin/pm-suspend
Source: How do I run specific sudo commands without a password?
Step two: create batwatch.desktop file:
This is the file that will launch automatically the monitoring script. The file must be stored in $HOME/.config/autostart/
folder.
[Desktop Entry]
Type=Application
Exec=/home/serg/bin/batwatch.sh
Hidden=false
NoDisplay=false
Name=Battery Monitor Script
Notice that the script is in my /home/serg/bin
folder. You can use whatever folder you like, but for the sake of standards /usr/bin or /home/username/bin would be more prefered.
Source: How to run a script on startup
Step three:create the actual script, save in the same location as Exec= line
Here's the actual script. Notice, I'm using bash there, but it also should work with korn shell. I added some comments, so read those to understand what the script does exactly
#!/bin/bash
# Check if the battery is connected
if [ -e /sys/class/power_supply/BAT1 ]; then
# this line is for debugging mostly. Could be removed
#notify-send --icon=info "STARTED MONITORING BATERY"
zenity --warning --text "STARTED MONITORING BATERY"
while true;do
# Get the capacity
CAPACITY=$( cat /sys/class/power_supply/BAT1/uevent | grep -i capacity | cut -d'=' -f2 )
case $CAPACITY in
# do stuff when we hit 11 % mark
[0-9]|11)
# send warning and suspend only if battery is discharging
# i.e., no charger connected
STATUS=$( cat /sys/class/power_supply/BAT1/uevent | grep -i status | cut -d'=' -f2 )
if [ $(echo $STATUS) == "Discharging" ]; then
#notify-send --urgency=critical --icon=dialog-warning "LOW BATTERY! SUSPENDING IN 30 sec"
zenity --warning --text "LOW BATTERY! SUSPENDING IN 30 sec"
sleep 30
gnome-screensaver-command -l && sudo pm-suspend
break
fi
;;
*)
sleep 1
continue
;;
esac
done
fi
Step four: reboot and test if the script works
For this purpose you can adjust the number [0-9]|11)
to whatever value you like, for example 65)
to suspend at 65%. The you will suspend only if you're not connected to power supply (i.e, not charging).
Let me know if you like this, and if it works, make sure to upvote and click the grey checkmark to the left side of my answer !
Cheers !
By default cron
sends mail to the email address mentioned in the MAILTO
environment variable on crontab
, presumably you have set the email address, so any STDOUT/STDERR from any cron
job will be sent to the email address.
The output is from /usr/lib/ubuntu-release-upgrader/release-upgrade-motd
script (run by the weekly job /etc/cron.weekly/update-notifier-common
) that checks for a new version, and dump the content of /var/lib/ubuntu-release-upgrader/release-upgrade-available
file.
You have a few options:
Disable the job
Redirect STDOUT/STDERR from the script to /dev/null
Set MAILTO=""
so that no mail will be sent. As /usr/sbin/anacron
exists the script will be run by anacron
, so setting this in /etc/anacrontab
would do too.
Best Answer
That output is part of the MOTD. To disable it, remove the execute permissions for
/etc/update-motd.d/90-updates-available
.The output maybe cached for a while, it may take a few login attempts for the message to clear out.