aboutsummaryrefslogtreecommitdiff
path: root/cmd/uptime
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-05-21 18:56:19 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-05-21 18:56:19 +0200
commit688779fbc61d48046199d1f45549720e289ce417 (patch)
tree4ea8c13d96428176f97c0c27f665391c09a93098 /cmd/uptime
parentfb0fd67d6e7e55548c7a0a1ec67f608efffe3a94 (diff)
downloadxmppcb-688779fbc61d48046199d1f45549720e289ce417.tar.gz
xmppcb-688779fbc61d48046199d1f45549720e289ce417.zip
Added support for user generated shell scripts:
- create a director with shell scripts - call them within the chat with @<script-name> - four sample scripts
Diffstat (limited to 'cmd/uptime')
-rwxr-xr-xcmd/uptime29
1 files changed, 29 insertions, 0 deletions
diff --git a/cmd/uptime b/cmd/uptime
new file mode 100755
index 0000000..fef74a8
--- /dev/null
+++ b/cmd/uptime
@@ -0,0 +1,29 @@
+#!/bin/sh
+# @uptime - how long the xmppcb bot has been running
+#
+# The bot exec's this script directly, so its parent process ($PPID) is
+# the xmppcb process itself; ps tells us how long that process has run.
+
+secs=$(ps -o etimes= -p "$PPID" 2>/dev/null | tr -cd '0-9')
+
+if [ -n "$secs" ]; then
+ d=$(( secs / 86400 ))
+ h=$(( secs % 86400 / 3600 ))
+ m=$(( secs % 3600 / 60 ))
+ s=$(( secs % 60 ))
+ if [ "$d" -gt 0 ]; then up="${d}d ${h}h ${m}m ${s}s"
+ elif [ "$h" -gt 0 ]; then up="${h}h ${m}m ${s}s"
+ elif [ "$m" -gt 0 ]; then up="${m}m ${s}s"
+ else up="${s}s"
+ fi
+ echo "xmppcb up: $up"
+else
+ # fallback for a ps without 'etimes': raw elapsed string [dd-]hh:mm:ss
+ et=$(ps -o etime= -p "$PPID" 2>/dev/null | tr -d ' ')
+ if [ -n "$et" ]; then
+ echo "xmppcb up: $et"
+ else
+ echo "uptime: cannot read bot process (pid $PPID)"
+ exit 1
+ fi
+fi