battery


[ Пред. ] [ Содержание ] [ След. ]

battery


Created Воскресенье 20 октября 2019



*/15 * * * * /home/ncuser/nc_batt_cap_shutdown.sh > /dev/null 2>&1
#!/bin/bash
### Script idea taken from:
# http://www.schulz-alex.de/cms/index.php/homeautomation-homecontrol/hardwareplattformen/cubietruck/59-akku-fuer-cubietruck
LOG_NEW=""
LOG_FILE=/home/ncuser/battery_cap_shutdown.log
BATPARAM=`cat /sys/class/power_supply/axp20x-battery/uevent`
source /sys/class/power_supply/axp20x-battery/uevent
AC_POWER_SUPPLY_PRESENT=`cat /sys/class/power_supply/axp20x-ac/present`
### Execute script only if AC adapter is not plugged in
if [ ${AC_POWER_SUPPLY_PRESENT} -eq 0 ]; then
### No AC adapter plugged in
if ${POWER_SUPPLY_ONLINE} -eq 0 ; then
### If no battery installed or battery is not discharged
exit fi
if ${POWER_SUPPLY_ONLINE} -eq 1 && ${POWER_SUPPLY_CAPACITY} -le 10 ; then
if [ ! -f "$LOG_FILE" ]; then ### Create log file if it is not yet there
touch $LOG_FILE fi
LOG_NEW+="$(date +'%d.%m.%Y %H:%M:%S')\tBattery capacity too low: ${POWER_SUPPLY_CAPACITY}\n"
LOG_NEW+="$(date +'%d.%m.%Y %H:%M:%S')\tOutput server battery state:\n${BATPARAM}\n"
LOG_NEW+="$(date +'%d.%m.%Y %H:%M:%S')\tShut down system\n"
SUBJECT="[Server] - Shutdown - Battery capacity too low: ${POWER_SUPPLY_CAPACITY}"
TO="email@domain.tld"
LOG_NEW+="$(date +'%d.%m.%Y %H:%M:%S')\tSend email with battery state info to: ${TO}\n"
printf "$LOG_NEW" >> "$LOG_FILE"
echo -e "$LOG_NEW" | sudo -u ncuser mutt -s "$SUBJECT" "$TO" -a $LOG_FILE ### Shutdown command taken from:
# http://chris.cnie.de/raspberrypi/cubietruck.html
sudo shutdown -P -h +0 # sudo poweroff -h
exit fi
else
### AC adapter plugged in => exit, no battery support required
exit
fi












Содержание