#!/bin/bash # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands an functions here ... export res # your additional bahsbot commands ... mycommands() { case "$MESSAGE" in '/run_'*) myback="run_${MESSAGE#*_}" if [ -x "./$myback.sh" ]; then checkback "$myback" if [ "$res" -gt 0 ] ; then send_normal_message "${CHAT[ID]}" "Starte $myback" background "./$myback.sh" "$myback" else send_normal_message "${CHAT[ID]}" "Prozess $myback laeuft bereits." fi fi ;; '/kill_'*) myback="run_${MESSAGE#*_}" if [ -x "./$myback.sh" ]; then checkback "$myback" if [ "$res" -eq 0 ] ; then killback "$myback" send_normal_message "${CHAT[ID]}" "Beende $myback." else send_normal_message "${CHAT[ID]}" "Prozess $myback laeuft nicht." fi fi ;; esac } # place your additional processing functions here ... # returns true if function exist _is_function() { [ "$(LC_ALL=C type -t "$1")" = "function" ] } # inifnite loop for waching a given dir for new files # $1 dir to wtach for new files watch_dir_loop() { local newfile old # wait for new files in WATCHDIR inotifywait -q -m "$1" -e create --format "%f" \ | while true do # read in newfile read -r newfile #skip if not match or same name as last time [ "${newfile}" = "${old}" ] && continue sleep 0.2 # process content and output message echo "$(date) found ${newfile}" >&2 # note: loop callback must a function in the calling script! if _is_function loop_callback ; then loop_callback "$1/$newfile" else echo "ERROR: loop_callback not found!" >&2 fi done } # 2>>"$0.log" output_telegram() { # output to telegram sed <<< "${1}" -e ':a;N;$!ba;s/\n/ mynewlinestartshere /g' } # 2>>"$0.log" # name and localtion of the tml file # $1 string to output # $2 file to add file to output_html_file() { local date date="$(date)" output_file "$(sed <<< "