Pi66

pino-rs
Rust notification daemon.
git clone https://git.pi66.xyz/pino-rs

← back to log

Add some usefull monitoring scripts

author: pixel
date: 2025-04-15 21:55
hash: 0358bccaadcae4ee552dc83fc6e5d5b0dcc6a72a

Diffstat:

M

scripts/battery-monitor.sh
8 ++++--------------------------
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
diff --git a/scripts/battery-monitor.sh b/scripts/battery-monitor.sh
index c642220..11dd259 100755
--- a/scripts/battery-monitor.sh
+++ b/scripts/battery-monitor.sh
@@ -1,11 +1,9 @@
 #!/bin/bash

-# Battery Monitor - Fixed and Optimized
 UP_THRESHOLD=90
 DOWN_THRESHOLD=20
 CHECK_INTERVAL=0.3

-# Find battery path (more reliable method)
 BATTERY_PATH=$(find /sys/class/power_supply/ -name "BAT*" | head -1)
 AC_PATH=$(find /sys/class/power_supply/ -name "AC*" | head -1)
 [ -z "$BATTERY_PATH" ] && echo "No battery found" && exit 1
@@ -17,19 +15,15 @@ while true; do
     level=<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mo stretchy="false">&#x00028;</mo><mi>c</mi><mi>a</mi><mi>t</mi><mi>"</mi></mrow></math>BATTERY_PATH/capacity")
     ac_status=<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mo stretchy="false">&#x00028;</mo><mi>c</mi><mi>a</mi><mi>t</mi><mi>"</mi></mrow></math>AC_PATH/online" 2>/dev/null || echo "0")

-    # 1. Plug detection (AC status changed from 0 to 1)
     if [ "<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>a</mi><msub><mi>c</mi><mi>s</mi></msub><mi>t</mi><mi>a</mi><mi>t</mi><mi>u</mi><mi>s</mi><mi>"</mi><mo>&#x02212;</mo><mi>e</mi><mi>q</mi><mn>1</mn><mo stretchy="false">]</mo><mi>&</mi><mi>&</mi><mo stretchy="false">[</mo><mi>"</mi></mrow></math>last_ac_status" -eq 0 ]; then
         pino -t "Plugged In" -m "Now charging ($level%)" -d 5
-    
-    # 2. Unplug detection (AC status changed from 1 to 0)
+
     elif [ "<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>a</mi><msub><mi>c</mi><mi>s</mi></msub><mi>t</mi><mi>a</mi><mi>t</mi><mi>u</mi><mi>s</mi><mi>"</mi><mo>&#x02212;</mo><mi>e</mi><mi>q</mi><mn>0</mn><mo stretchy="false">]</mo><mi>&</mi><mi>&</mi><mo stretchy="false">[</mo><mi>"</mi></mrow></math>last_ac_status" -eq 1 ]; then
         pino -t "Unplugged" -m "On battery ($level%)" -d 5

-    # 3. Crossed above 90% (only when discharging)
     elif [ "<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>l</mi><mi>e</mi><mi>v</mi><mi>e</mi><mi>l</mi><mi>"</mi><mo>&#x02212;</mo><mi>g</mi><mi>e</mi></mrow></math>UP_THRESHOLD ] && [ "<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>l</mi><mi>a</mi><mi>s</mi><msub><mi>t</mi><mi>l</mi></msub><mi>e</mi><mi>v</mi><mi>e</mi><mi>l</mi><mi>"</mi><mo>&#x02212;</mo><mi>l</mi><mi>t</mi></mrow></math>UP_THRESHOLD ] && [ "$ac_status" -eq 0 ]; then
         pino -t "Battery High" -m "Reached $level%" -d 5

-    # 4. Crossed below 20% (only when discharging)
     elif [ "<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>l</mi><mi>e</mi><mi>v</mi><mi>e</mi><mi>l</mi><mi>"</mi><mo>&#x02212;</mo><mi>l</mi><mi>e</mi></mrow></math>DOWN_THRESHOLD ] && [ "<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>l</mi><mi>a</mi><mi>s</mi><msub><mi>t</mi><mi>l</mi></msub><mi>e</mi><mi>v</mi><mi>e</mi><mi>l</mi><mi>"</mi><mo>&#x02212;</mo><mi>g</mi><mi>t</mi></mrow></math>DOWN_THRESHOLD ] && [ "$ac_status" -eq 0 ]; then
         pino -t "Battery Low" -m "Only $level% left" -d 5
     fi