telegram-bot-bash/examples/send-system-status/mycommands.sh

70 lines
1.9 KiB
Bash
Raw Normal View History

2019-04-30 13:48:55 +00:00
#!/bin/bash
# files: mycommands.sh
#
# this example is rendered after https://github.com/RG72/telegram-bot-bash
# to show how you can customize bashbot by only editing mycommands.sh
# NOTE: this is not tested, simply copied from original source and reworked!
#
2020-05-20 14:38:56 +00:00
#### $$VERSION$$ v0.96-dev-7-g0153928
2019-04-30 13:48:55 +00:00
#
# shellcheck disable=SC2154
# shellcheck disable=SC2034
# uncomment the following lines to overwrite info and help messages
#'
# returned messages
bashbot_info='This bot allows you to request status of your system.
To begin using the bot, try with the /help command.
'
bashbot_help='*Availiable commands*:
/se *sensors*
/smb *smbstatus*
2019-04-30 13:48:55 +00:00
/free *memory status*
/md *raid status*
/lvm *lvm status*
2019-04-30 13:48:55 +00:00
/lvsd *Datailed lvm status*
/df *disk space*
/ifconfig *ifconfig output*
/smart *-d sda* _smart status for sda drive_
'
# your additional bahsbot commands
# NOTE: command can have @botname attached, you must add * in case tests...
mycommands() {
local msg=""
2019-05-02 09:10:55 +00:00
if user_is_botadmin "${USER[ID]}" || user_is_allowed "${USER[ID]}" "systemstatus"; then
2019-06-01 10:46:27 +00:00
case "$CMD" in
'/md'*) msg="$(cat /proc/mdstat)";;
'/smb'*) msg="$(smbstatus)" ;;
'/se'*) msg="$(sensors | sed -r 's/\s|\)+//g' | sed -r 's/\(high=|\(min=/\//' | sed -r 's/\,crit=|\,max=/\//')";;
'/free'*) msg="$(free -h)";;
'/pvs'*) msg="$(pvs)";;
'/ifc'*) msg="$(ifconfig)";;
'/vgs'*) msg="$(vgs)";;
'/lvm'*) msg="$(lvs | sed -r 's/\s+/\n/g')";;
'/lvsd'*) msg="$(lvs -a -o +devices | sed -r 's/\s+/\n/g')";;
'/smart'*)
2019-06-01 10:46:27 +00:00
[ "${CMD[1]}" == "" ] && msg="example \`/smart sda\`" && return
drive="$(echo "${CMD[1]}" | cut -c 1-3)"
echo "smartctl -a /dev/$drive"
msg="$(smartctl -a "/dev/$drive")"
2019-04-30 13:48:55 +00:00
;;
'/df') msg="$(df -h | sed -r 's/^/\n/' | sed -r 's/\s+/\n/g')";;
esac
if [ "$msg" != "" ]; then
send_normal_message "${CHAT[ID]}" "$msg"
2019-04-30 13:48:55 +00:00
fi
else
send_normal_message "${USER[ID]}" "Sorry, you are not allowed to use this bot!"
2019-04-30 13:48:55 +00:00
fi
}
# place your processing functions here