add examples for background and checkproc to commands.sh

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-03-18 15:32:17 +01:00
parent b181234bb9
commit e5d0b5d216
2 changed files with 46 additions and 2 deletions

View File

@ -49,8 +49,32 @@ else
fi
case "$MESSAGE" in
'/question')
startproc "./question"
checkproc
if [ $res -gt 0 ] ; then
startproc "./question"
else
send_normal_message "${CHAT[ID]}" "$MESSAGE already running ..."
fi
;;
'/run-notify')
myback="notify"; checkback "$myback"
if [ $res -gt 0 ] ; then
background "./notify 60" "$myback" # notify every 60 seconds
else
send_normal_message "${CHAT[ID]}" "Background command $myback already running ..."
fi
;;
'/stop-notify')
myback="notify"; checkback "$myback"
if [ $res -eq 0 ] ; then
killback "$myback"
send_normal_message "${CHAT[ID]}" "Background command $myback canceled."
else
send_normal_message "${CHAT[ID]}" "No background command $myback is currently running.."
fi
;;
'/info')
send_markdown_message "${CHAT[ID]}" "This is bashbot, the *Telegram* bot written entirely in *bash*."
;;
@ -82,7 +106,8 @@ Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash)
;;
'/cancel')
if tmux ls | grep -q $copname; then killproc && send_message "${CHAT[ID]}" "Command canceled.";else send_message "${CHAT[ID]}" "No command is currently running.";fi
checkprog
if [ $res -eq 0 ] ; then killproc && send_message "${CHAT[ID]}" "Command canceled.";else send_message "${CHAT[ID]}" "No command is currently running.";fi
;;
*)
if tmux ls | grep -v send | grep -q $copname;then inproc; else send_message "${CHAT[ID]}" "$MESSAGE" "safe";fi

19
notify Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# check if $1 is a number
re='^[0-9]+$'
if [[ $1 =~ $re ]] ; then
SLEEP="$1"
else
SLEEP=10 # time between time notifications
fi
# output current time every $1 seconds
while sleep $SLEEP
do
date "+* It's %k:%M:%S o' clock ..."
done