check remote queues
authorIan Kelling <ian@iankelling.org>
Thu, 17 Oct 2019 21:20:12 +0000 (17:20 -0400)
committerIan Kelling <ian@iankelling.org>
Thu, 17 Oct 2019 21:20:12 +0000 (17:20 -0400)
brc
brc2
system-status

diff --git a/brc b/brc
index ad1a0781c291eb0652cd1b3a04ff50d067b34598..fe6528acd093ca63a4c9e4674ef63ae5bdaaa774 100644 (file)
--- a/brc
+++ b/brc
@@ -746,6 +746,7 @@ nopanic() {
 }
 
 p8() { ping 8.8.8.8; }
+p6() { ping6 2001:4860:4860::8888; }
 
 pkx() { # package extract
   local pkg cached tmp f
diff --git a/brc2 b/brc2
index 7c33bea3251ebbd08cea977f6b72dff156be36d2..bff0eb755462d8ee91cd3f31cda1ac340e84db73 100644 (file)
--- a/brc2
+++ b/brc2
@@ -127,13 +127,13 @@ lipushnoe() {
 }
 
 
+#### begin bitcoin related things
 btc() {
   local f=/etc/bitcoin/bitcoin.conf
   # importprivkey will timeout if using the default of 15 mins.
   # upped it to 1 hour.
   bitcoin-cli -rpcclienttimeout=60000 -$(s grep rpcuser= $f) -$(s grep rpcpassword= $f) "$@"
 }
-
 btcusd() { # $1 btc in usd
   local price
   price="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
@@ -160,6 +160,7 @@ satoshi() { # $1 satoshi in usd
     printf "$%.2f\n" "$(echo "scale=10; $price * $1"| bc -l)"
   fi
 }
+#### end bitcoin related things
 
 
 
@@ -227,7 +228,25 @@ debian_pick_mirror () {
   sudo apt-get update
 }
 
-
+dup() {
+  local ran_d
+  ran_d=false
+  case $PS1 in
+    *DISTRO-BEGIN*)
+      /b/ds/distro-begin
+      ran_d=true
+      ;;&
+    *DISTRO-END*)
+      /b/ds/distro-end
+      ran_d=true
+      ;;&
+    *CONFLINK*)
+      if ! $ran_d; then
+        conflink
+      fi
+      ;;
+  esac
+}
 
 envload() { # load environment from a previous: export > file
   local file=${1:-$HOME/.${USER}_env}
index b8e854dbff25b158575aaa99eaadbb21eb734690..e01b15b6346af812f68779b88dcb4d2864f274de 100755 (executable)
@@ -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
@@ -96,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"
@@ -134,11 +136,38 @@ write-status() {
   fi
 
 }
+first_chars=()
+
+power=true
+if [[ -e /sys/class/power_supply/AC/online && $(</sys/class/power_supply/AC/online) == 0 ]]; then
+  power=false
+fi
+
+if $power; then
+  for h in tp.b8.nz vpn1 x2 x3.b8.nz frodo.b8.nz kd.b8.nz kw; do
+    if [[ $HOSTNAME == ${h%%.*} ]]; then
+      continue
+    fi
+    msg=
+    if c=$(timeout 1 ssh $h exim -bpc 2>/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