X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=system-status;h=e01b15b6346af812f68779b88dcb4d2864f274de;hb=2f7b266e782347022b68c5c8e8fbe9292492c343;hp=25a637ee9606788c97e22949b470a811428abf16;hpb=7e4f3d0a6130b69b7f76a3ff13e510ffbeb1484b;p=distro-setup diff --git a/system-status b/system-status index 25a637e..e01b15b 100755 --- a/system-status +++ b/system-status @@ -2,7 +2,8 @@ # Copyright (C) 2019 Ian Kelling # SPDX-License-Identifier: AGPL-3.0-or-later -# usage: runs 4 times every 15 seconds unless any args are passed, then just runs once +# usage: runs 4 times every 15 seconds unless any args are passed, or we +# are on battery power, then just runs once. if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi @@ -15,7 +16,7 @@ shopt -s dotglob lo() { /usr/local/bin/log-once "$@"; } write-status() { - chars=() + chars=("${first_chars[@]}") glob=(/nocow/btrfs-stale/*) if [[ -e ${glob[0]} ]]; then @@ -35,6 +36,10 @@ write-status() { chars+=("MAILPING!") fi + qlen=$(/usr/sbin/exim -bpc) + if ((qlen)); then + chars+=("q $qlen") + fi if ! make -q ~/.local/distro-begin || [[ $(<~/.local/distro-begin) != 0 ]]; then chars+=("DISTRO-BEGIN!") @@ -92,6 +97,7 @@ write-status() { source /a/bin/bash_unpublished/source-state if [[ $MAIL_HOST == "$HOSTNAME" ]]; then + bbkmsg= if [[ $(systemctl is-active btrbk.timer) != active ]]; then chars+=("BTRBK.TIMER!") bbkmsg="btrbk.timer not enabled" @@ -100,7 +106,13 @@ write-status() { ## check if last snapshot was within an hour vol=o - snaps=(/mnt/root/btrbk/$vol.20*) + # this section generally copied from btrbk scripts, but + # this part modified to speed things up by about half a second. + # I'm not sure if its quite as reliable, but it looks pretty safe. + # Profiled it using time and also adding to the top of the file: + # set -x + # PS4='+ $(date "+%2N") ' + snaps=($(ls -1avdr /mnt/root/btrbk/$vol.20*|head -n1)) now=$(date +%s) maxtime=0 for s in ${snaps[@]}; do @@ -124,11 +136,38 @@ write-status() { fi } +first_chars=() + +power=true +if [[ -e /sys/class/power_supply/AC/online && $(/dev/null) && [[ $c && $c != 0 ]]; then + msg=q:$h=$c + first_chars+=($msg) + fi + if [[ $1 ]]; then + echo q: $h $c + fi + lo -1 remote-mailq $msg + done +fi write-status if [[ $1 ]]; then cat $status_file exit 0 fi + +if ! $power; then + exit 0 +fi for ((i=1; i<=3; i++)); do sleep 15 write-status