samedi 31 janvier 2015

Why do I get mail when I unplug my adapter?


Usually I only get the terminal output You have new mail in /var/mail/$USER after running certain upgrades but I've started getting it every couple days after running other commands, seemingly at random. The new mail in /var/mail/$USER is always to akin to this:



Message-Id: <E1YHfKT-0008LI-2d@debianator>
From: root <root@debianator>
Date: Sat, 31 Jan 2015 22:11:45 +0100

Adapter 0: off-line


Note that it doesn't happen every time i plug put the AC adapter (thank God)!


I use a simple bash script (run by udev) to hibernate when battery is low and the AC adapter isn't connected. The script uses acpi to detect the latter and has been working for years without mailing me.


So what service could be mailing Adapter 0: off-line to me?


EDIT:


Below is the script I use to hibernate on low battery. On further inspection, I definitely think it's related. Note the if acpi -a | grep 'off-line' lines. When I run acpi -a | grep 'off-line I get the output Adapter 0: off-line. That is the exact output that is send to my mail - so how do I stop it?


Here is the script:



#!/bin/bash
# Critical battery level (acpi reports it at 5%)
CRITICAL=6

battery_level=`acpi -b | grep -o [0-9]*% | sed s/%//`
if [ ! $battery_level ]
then
exit
fi
if [ $battery_level -le $CRITICAL ]
then
if acpi -a | grep 'off-line'
then
# Warning
sudo -u andreas DISPLAY=":0.0" notify-send -u critical "Gimme power"
sleep 60s
if acpi -a | grep 'off-line'
then

sudo -u andreas DISPLAY=":0.0" notify-send -u critical "Shutting down"
sleep 2s
/bin/systemctl hibernate
fi
fi


Aucun commentaire:

Enregistrer un commentaire