From 688779fbc61d48046199d1f45549720e289ce417 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Thu, 21 May 2026 18:56:19 +0200 Subject: Added support for user generated shell scripts: - create a director with shell scripts - call them within the chat with @ - four sample scripts --- cmd/uptime | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 cmd/uptime (limited to 'cmd/uptime') 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 -- cgit v1.3