mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-25 00:37:34 +00:00
example/: fix missing ${xxx}
This commit is contained in:
parent
9ef8778f85
commit
248a065be4
@ -6,12 +6,12 @@ export res
|
||||
# your additional bashbot commands ...
|
||||
mycommands() {
|
||||
|
||||
case "$MESSAGE" in
|
||||
case "${MESSAGE}" in
|
||||
'/run_'*)
|
||||
myback="run_${MESSAGE#*_}"
|
||||
if [ -x "./${myback}.sh" ]; then
|
||||
checkback "${myback}"
|
||||
if [ "$res" -gt 0 ] ; then
|
||||
if [ "${res}" -gt 0 ] ; then
|
||||
send_normal_message "${CHAT[ID]}" "Start ${myback}, use /kill${myback} to stop it."
|
||||
background "./${myback}.sh" "${myback}"
|
||||
else
|
||||
@ -23,7 +23,7 @@ mycommands() {
|
||||
myback="run_${MESSAGE#*_}"
|
||||
if [ -x "./${myback}.sh" ]; then
|
||||
checkback "${myback}"
|
||||
if [ "$res" -eq 0 ] ; then
|
||||
if [ "${res}" -eq 0 ] ; then
|
||||
killback "${myback}"
|
||||
send_normal_message "${CHAT[ID]}" "Stopping ${myback}, use /run_${myback} to start again."
|
||||
else
|
||||
@ -56,7 +56,7 @@ watch_dir_loop() {
|
||||
echo "$(date): new file: ${newfile}" >>"$0.log"
|
||||
# note: loop callback must a function in the calling script!
|
||||
if _is_function loop_callback ; then
|
||||
loop_callback "$1/$newfile"
|
||||
loop_callback "$1/${newfile}"
|
||||
else
|
||||
echo "ERROR: loop_callback not found!" >&2
|
||||
exit 1
|
||||
@ -94,8 +94,8 @@ output_file() {
|
||||
sed <<< "${1}" '
|
||||
s/ *mynewlinestartshere */\n/
|
||||
s/ my[a-z]\{3,15}\(start\|ends\)here.*//g
|
||||
' >"$publish$$"
|
||||
cat "$publish" >>"$publish$$"
|
||||
' >"${publish}$$"
|
||||
cat "${publish}" >>"${publish}$$"
|
||||
mv "${publish}$$" "${publish}"
|
||||
} # >>"$0.log" 2>&1
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
#
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#### $$VERSION$$ v1.21-0-gc85af77
|
||||
#### $$VERSION$$ v1.25-dev-7-g9ef8778
|
||||
|
||||
######
|
||||
# parameters
|
||||
@ -28,8 +28,8 @@ cat >/dev/null &
|
||||
source "./mycommands.sh"
|
||||
|
||||
# check if $1 is a number
|
||||
re='^[0-9]+$'
|
||||
if [[ $1 =~ $re ]] ; then
|
||||
regex='^[0-9]+$'
|
||||
if [[ $1 =~ ${regex} ]] ; then
|
||||
SLEEP="$1"
|
||||
else
|
||||
SLEEP=100 # time between time notifications
|
||||
@ -39,11 +39,11 @@ NEWLINE=$'\n'
|
||||
|
||||
# output disk usage every $1 seconds
|
||||
WAIT=0
|
||||
while sleep $WAIT
|
||||
while sleep "${WAIT}"
|
||||
do
|
||||
output_telegram "Current Disk usage ${NEWLINE} $(df -h / /tmp /usr /var /home)"
|
||||
# only for testing, delete echo line for production ...
|
||||
echo "Current Disk usage ${NEWLINE} $(df -h / /tmp /usr /var /home)"
|
||||
WAIT="$SLEEP"
|
||||
WAIT="${SLEEP}"
|
||||
done
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
# file: run_filename
|
||||
# background job to display content of all new files in WATCHDIR
|
||||
#
|
||||
#### $$VERSION$$ v1.21-0-gc85af77
|
||||
#### $$VERSION$$ v1.25-dev-7-g9ef8778
|
||||
|
||||
######
|
||||
# parameters
|
||||
@ -40,4 +40,4 @@ loop_callback() {
|
||||
output_telegram "Contents of ${1}: ${NEWLINE} $(cat "${1}")"
|
||||
}
|
||||
|
||||
watch_dir_loop "$WATCHDIR"
|
||||
watch_dir_loop "${WATCHDIR}"
|
||||
|
@ -2,7 +2,7 @@
|
||||
# file: run_filename
|
||||
# background job to display all new files in WATCHDIR
|
||||
#
|
||||
#### $$VERSION$$ v1.21-0-gc85af77
|
||||
#### $$VERSION$$ v1.25-dev-7-g9ef8778
|
||||
|
||||
######
|
||||
# parameters
|
||||
@ -38,5 +38,5 @@ loop_callback() {
|
||||
echo "New file ${1} created in ${WATCHDIR}!"
|
||||
}
|
||||
|
||||
watch_dir_loop "$WATCHDIR"
|
||||
watch_dir_loop "${WATCHDIR}"
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
#
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#### $$VERSION$$ v1.21-0-gc85af77
|
||||
#### $$VERSION$$ v1.25-dev-7-g9ef8778
|
||||
|
||||
######
|
||||
# parameters
|
||||
@ -25,15 +25,15 @@ unset IFS
|
||||
cat >/dev/null &
|
||||
|
||||
# check if $1 is a number
|
||||
re='^[0-9]+$'
|
||||
if [[ $1 =~ $re ]] ; then
|
||||
regex='^[0-9]+$'
|
||||
if [[ "$1" =~ ${regex} ]] ; then
|
||||
SLEEP="$1"
|
||||
else
|
||||
SLEEP=10 # time between time notifications
|
||||
fi
|
||||
|
||||
# output current time every $1 seconds
|
||||
while sleep $SLEEP
|
||||
while sleep "${SLEEP}"
|
||||
do
|
||||
date "+* It's %k:%M:%S o' clock ..."
|
||||
done
|
||||
|
@ -10,7 +10,7 @@
|
||||
# AUTHOR: KayM (), kay@rrr.de
|
||||
# DATE: 19.12.2020 19:03
|
||||
#
|
||||
#### $$VERSION$$ v1.21-0-gc85af77
|
||||
#### $$VERSION$$ v1.25-dev-7-g9ef8778
|
||||
#===============================================================================
|
||||
# shellcheck disable=SC2154
|
||||
# shellcheck disable=SC2034
|
||||
@ -326,8 +326,8 @@ fi
|
||||
MYKEYF="$2"
|
||||
MINLEN="4"
|
||||
# check len of keys
|
||||
for MYKEY in ${MYFIND}; do [ "${#MYKEY}" -lt ${MINLEN} ] && break; done
|
||||
if [ "${#MYKEY}" -lt ${MINLEN} ]; then
|
||||
for MYKEY in ${MYFIND}; do [ "${#MYKEY}" -lt "${MINLEN}" ] && break; done
|
||||
if [ "${#MYKEY}" -lt "${MINLEN}" ]; then
|
||||
send_markdownv2_message "${CHAT[ID]}" "*Ein Suchbegriff ist kürzer als ${MINLEN} Zeichen!*"
|
||||
else
|
||||
MYFIND="$(create_pattern "${MYFIND}")"
|
||||
|
@ -5,7 +5,7 @@
|
||||
# to show how you can customize bashbot by only editing mycommands.sh
|
||||
# NOTE: this is not tested, simply copied from original source and reworked!
|
||||
#
|
||||
#### $$VERSION$$ v1.21-0-gc85af77
|
||||
#### $$VERSION$$ v1.25-dev-7-g9ef8778
|
||||
#
|
||||
# shellcheck disable=SC2154
|
||||
# shellcheck disable=SC2034
|
||||
@ -38,7 +38,7 @@ mycommands() {
|
||||
local msg=""
|
||||
|
||||
if user_is_botadmin "${USER[ID]}" || user_is_allowed "${USER[ID]}" "systemstatus"; then
|
||||
case "$CMD" in
|
||||
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=/\//')";;
|
||||
@ -51,14 +51,14 @@ mycommands() {
|
||||
'/smart'*)
|
||||
[ "${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")"
|
||||
echo "smartctl -a /dev/${drive}"
|
||||
msg="$(smartctl -a "/dev/${drive}")"
|
||||
;;
|
||||
'/df') msg="$(df -h | sed -r 's/^/\n/' | sed -r 's/\s+/\n/g')";;
|
||||
esac
|
||||
|
||||
if [ "$msg" != "" ]; then
|
||||
send_normal_message "${CHAT[ID]}" "$msg"
|
||||
if [ "${msg}" != "" ]; then
|
||||
send_normal_message "${CHAT[ID]}" "${msg}"
|
||||
fi
|
||||
else
|
||||
send_normal_message "${USER[ID]}" "Sorry, you are not allowed to use this bot!"
|
||||
|
Loading…
Reference in New Issue
Block a user