example/: fix missing ${xxx}

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2021-01-05 11:58:30 +01:00
parent 9ef8778f85
commit 248a065be4
7 changed files with 28 additions and 28 deletions

View File

@ -6,12 +6,12 @@ export res
# your additional bashbot commands ... # your additional bashbot commands ...
mycommands() { mycommands() {
case "$MESSAGE" in case "${MESSAGE}" in
'/run_'*) '/run_'*)
myback="run_${MESSAGE#*_}" myback="run_${MESSAGE#*_}"
if [ -x "./${myback}.sh" ]; then if [ -x "./${myback}.sh" ]; then
checkback "${myback}" 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." send_normal_message "${CHAT[ID]}" "Start ${myback}, use /kill${myback} to stop it."
background "./${myback}.sh" "${myback}" background "./${myback}.sh" "${myback}"
else else
@ -23,7 +23,7 @@ mycommands() {
myback="run_${MESSAGE#*_}" myback="run_${MESSAGE#*_}"
if [ -x "./${myback}.sh" ]; then if [ -x "./${myback}.sh" ]; then
checkback "${myback}" checkback "${myback}"
if [ "$res" -eq 0 ] ; then if [ "${res}" -eq 0 ] ; then
killback "${myback}" killback "${myback}"
send_normal_message "${CHAT[ID]}" "Stopping ${myback}, use /run_${myback} to start again." send_normal_message "${CHAT[ID]}" "Stopping ${myback}, use /run_${myback} to start again."
else else
@ -56,7 +56,7 @@ watch_dir_loop() {
echo "$(date): new file: ${newfile}" >>"$0.log" echo "$(date): new file: ${newfile}" >>"$0.log"
# note: loop callback must a function in the calling script! # note: loop callback must a function in the calling script!
if _is_function loop_callback ; then if _is_function loop_callback ; then
loop_callback "$1/$newfile" loop_callback "$1/${newfile}"
else else
echo "ERROR: loop_callback not found!" >&2 echo "ERROR: loop_callback not found!" >&2
exit 1 exit 1
@ -94,8 +94,8 @@ output_file() {
sed <<< "${1}" ' sed <<< "${1}" '
s/ *mynewlinestartshere */\n/ s/ *mynewlinestartshere */\n/
s/ my[a-z]\{3,15}\(start\|ends\)here.*//g s/ my[a-z]\{3,15}\(start\|ends\)here.*//g
' >"$publish$$" ' >"${publish}$$"
cat "$publish" >>"$publish$$" cat "${publish}" >>"${publish}$$"
mv "${publish}$$" "${publish}" mv "${publish}$$" "${publish}"
} # >>"$0.log" 2>&1 } # >>"$0.log" 2>&1

View File

@ -4,7 +4,7 @@
# #
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ v1.21-0-gc85af77 #### $$VERSION$$ v1.25-dev-7-g9ef8778
###### ######
# parameters # parameters
@ -28,8 +28,8 @@ cat >/dev/null &
source "./mycommands.sh" source "./mycommands.sh"
# check if $1 is a number # check if $1 is a number
re='^[0-9]+$' regex='^[0-9]+$'
if [[ $1 =~ $re ]] ; then if [[ $1 =~ ${regex} ]] ; then
SLEEP="$1" SLEEP="$1"
else else
SLEEP=100 # time between time notifications SLEEP=100 # time between time notifications
@ -39,11 +39,11 @@ NEWLINE=$'\n'
# output disk usage every $1 seconds # output disk usage every $1 seconds
WAIT=0 WAIT=0
while sleep $WAIT while sleep "${WAIT}"
do do
output_telegram "Current Disk usage ${NEWLINE} $(df -h / /tmp /usr /var /home)" output_telegram "Current Disk usage ${NEWLINE} $(df -h / /tmp /usr /var /home)"
# only for testing, delete echo line for production ... # only for testing, delete echo line for production ...
echo "Current Disk usage ${NEWLINE} $(df -h / /tmp /usr /var /home)" echo "Current Disk usage ${NEWLINE} $(df -h / /tmp /usr /var /home)"
WAIT="$SLEEP" WAIT="${SLEEP}"
done done

View File

@ -2,7 +2,7 @@
# file: run_filename # file: run_filename
# background job to display content of all new files in WATCHDIR # background job to display content of all new files in WATCHDIR
# #
#### $$VERSION$$ v1.21-0-gc85af77 #### $$VERSION$$ v1.25-dev-7-g9ef8778
###### ######
# parameters # parameters
@ -40,4 +40,4 @@ loop_callback() {
output_telegram "Contents of ${1}: ${NEWLINE} $(cat "${1}")" output_telegram "Contents of ${1}: ${NEWLINE} $(cat "${1}")"
} }
watch_dir_loop "$WATCHDIR" watch_dir_loop "${WATCHDIR}"

View File

@ -2,7 +2,7 @@
# file: run_filename # file: run_filename
# background job to display all new files in WATCHDIR # background job to display all new files in WATCHDIR
# #
#### $$VERSION$$ v1.21-0-gc85af77 #### $$VERSION$$ v1.25-dev-7-g9ef8778
###### ######
# parameters # parameters
@ -38,5 +38,5 @@ loop_callback() {
echo "New file ${1} created in ${WATCHDIR}!" echo "New file ${1} created in ${WATCHDIR}!"
} }
watch_dir_loop "$WATCHDIR" watch_dir_loop "${WATCHDIR}"

View File

@ -4,7 +4,7 @@
# #
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ v1.21-0-gc85af77 #### $$VERSION$$ v1.25-dev-7-g9ef8778
###### ######
# parameters # parameters
@ -25,15 +25,15 @@ unset IFS
cat >/dev/null & cat >/dev/null &
# check if $1 is a number # check if $1 is a number
re='^[0-9]+$' regex='^[0-9]+$'
if [[ $1 =~ $re ]] ; then if [[ "$1" =~ ${regex} ]] ; then
SLEEP="$1" SLEEP="$1"
else else
SLEEP=10 # time between time notifications SLEEP=10 # time between time notifications
fi fi
# output current time every $1 seconds # output current time every $1 seconds
while sleep $SLEEP while sleep "${SLEEP}"
do do
date "+* It's %k:%M:%S o' clock ..." date "+* It's %k:%M:%S o' clock ..."
done done

View File

@ -10,7 +10,7 @@
# AUTHOR: KayM (), kay@rrr.de # AUTHOR: KayM (), kay@rrr.de
# DATE: 19.12.2020 19:03 # DATE: 19.12.2020 19:03
# #
#### $$VERSION$$ v1.21-0-gc85af77 #### $$VERSION$$ v1.25-dev-7-g9ef8778
#=============================================================================== #===============================================================================
# shellcheck disable=SC2154 # shellcheck disable=SC2154
# shellcheck disable=SC2034 # shellcheck disable=SC2034
@ -326,8 +326,8 @@ fi
MYKEYF="$2" MYKEYF="$2"
MINLEN="4" MINLEN="4"
# check len of keys # check len of keys
for MYKEY in ${MYFIND}; do [ "${#MYKEY}" -lt ${MINLEN} ] && break; done for MYKEY in ${MYFIND}; do [ "${#MYKEY}" -lt "${MINLEN}" ] && break; done
if [ "${#MYKEY}" -lt ${MINLEN} ]; then if [ "${#MYKEY}" -lt "${MINLEN}" ]; then
send_markdownv2_message "${CHAT[ID]}" "*Ein Suchbegriff ist kürzer als ${MINLEN} Zeichen!*" send_markdownv2_message "${CHAT[ID]}" "*Ein Suchbegriff ist kürzer als ${MINLEN} Zeichen!*"
else else
MYFIND="$(create_pattern "${MYFIND}")" MYFIND="$(create_pattern "${MYFIND}")"

View File

@ -5,7 +5,7 @@
# to show how you can customize bashbot by only editing mycommands.sh # to show how you can customize bashbot by only editing mycommands.sh
# NOTE: this is not tested, simply copied from original source and reworked! # 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=SC2154
# shellcheck disable=SC2034 # shellcheck disable=SC2034
@ -38,7 +38,7 @@ mycommands() {
local msg="" local msg=""
if user_is_botadmin "${USER[ID]}" || user_is_allowed "${USER[ID]}" "systemstatus"; then if user_is_botadmin "${USER[ID]}" || user_is_allowed "${USER[ID]}" "systemstatus"; then
case "$CMD" in case "${CMD}" in
'/md'*) msg="$(cat /proc/mdstat)";; '/md'*) msg="$(cat /proc/mdstat)";;
'/smb'*) msg="$(smbstatus)" ;; '/smb'*) msg="$(smbstatus)" ;;
'/se'*) msg="$(sensors | sed -r 's/\s|\)+//g' | sed -r 's/\(high=|\(min=/\//' | sed -r 's/\,crit=|\,max=/\//')";; '/se'*) msg="$(sensors | sed -r 's/\s|\)+//g' | sed -r 's/\(high=|\(min=/\//' | sed -r 's/\,crit=|\,max=/\//')";;
@ -51,14 +51,14 @@ mycommands() {
'/smart'*) '/smart'*)
[ "${CMD[1]}" == "" ] && msg="example \`/smart sda\`" && return [ "${CMD[1]}" == "" ] && msg="example \`/smart sda\`" && return
drive="$(echo "${CMD[1]}" | cut -c 1-3)" drive="$(echo "${CMD[1]}" | cut -c 1-3)"
echo "smartctl -a /dev/$drive" echo "smartctl -a /dev/${drive}"
msg="$(smartctl -a "/dev/$drive")" msg="$(smartctl -a "/dev/${drive}")"
;; ;;
'/df') msg="$(df -h | sed -r 's/^/\n/' | sed -r 's/\s+/\n/g')";; '/df') msg="$(df -h | sed -r 's/^/\n/' | sed -r 's/\s+/\n/g')";;
esac esac
if [ "$msg" != "" ]; then if [ "${msg}" != "" ]; then
send_normal_message "${CHAT[ID]}" "$msg" send_normal_message "${CHAT[ID]}" "${msg}"
fi fi
else else
send_normal_message "${USER[ID]}" "Sorry, you are not allowed to use this bot!" send_normal_message "${USER[ID]}" "Sorry, you are not allowed to use this bot!"