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!
|
|
|
|
#
|
2021-02-04 17:13:32 +00:00
|
|
|
#### $$VERSION$$ v1.40-0-gf9dab50
|
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.
|
|
|
|
'
|
2020-06-23 14:35:50 +00:00
|
|
|
bashbot_help='*Available commands*:
|
2019-05-01 09:46:57 +00:00
|
|
|
/se *sensors*
|
|
|
|
/smb *smbstatus*
|
2019-04-30 13:48:55 +00:00
|
|
|
/free *memory status*
|
|
|
|
/md *raid status*
|
2019-05-01 09:46:57 +00:00
|
|
|
/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_
|
|
|
|
'
|
|
|
|
|
|
|
|
|
2020-09-27 15:36:01 +00:00
|
|
|
# your additional bashbot commands
|
2019-04-30 13:48:55 +00:00
|
|
|
# NOTE: command can have @botname attached, you must add * in case tests...
|
|
|
|
mycommands() {
|
2019-05-01 09:46:57 +00:00
|
|
|
local msg=""
|
|
|
|
|
2019-05-02 09:10:55 +00:00
|
|
|
if user_is_botadmin "${USER[ID]}" || user_is_allowed "${USER[ID]}" "systemstatus"; then
|
2021-01-05 10:58:30 +00:00
|
|
|
case "${CMD}" in
|
2019-05-01 09:46:57 +00:00
|
|
|
'/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)"
|
2021-01-05 10:58:30 +00:00
|
|
|
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
|
|
|
|
|
2021-01-05 10:58:30 +00:00
|
|
|
if [ "${msg}" != "" ]; then
|
|
|
|
send_normal_message "${CHAT[ID]}" "${msg}"
|
2019-04-30 13:48:55 +00:00
|
|
|
fi
|
|
|
|
else
|
2019-05-01 09:46:57 +00:00
|
|
|
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
|
|
|
|
|