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

76 lines
2.1 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!
#
2019-05-16 15:06:58 +00:00
#### $$VERSION$$ v0.76-1-ge8a1fd0
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() {
[[ "$MESSAGE" = '/'* ]] || return
set +f
# shellcheck disable=SC2206
local arg=( $MESSAGE )
set -f
local cmd="${arg[0]}"
local msg=""
2019-05-02 09:10:55 +00:00
if user_is_botadmin "${USER[ID]}" || user_is_allowed "${USER[ID]}" "systemstatus"; then
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'*)
[ "${arg[0]}" == "" ] && msg="example \`/smart sda\`" && return
drive="$(echo "${arg[0]}" | 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