mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-30 21:31:47 +00:00
fix background execution
This commit is contained in:
parent
bccd064516
commit
a1a823b4b6
@ -12,7 +12,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$$ v0.80-dev3-0-g31a5d00
|
#### $$VERSION$$ v0.80-dev3-1-gbccd064
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 sucess (hopefully)
|
# - 0 sucess (hopefully)
|
||||||
@ -424,12 +424,11 @@ if [ "$1" != "source" ]; then
|
|||||||
"outproc") # forward output from interactive and jobs to chat
|
"outproc") # forward output from interactive and jobs to chat
|
||||||
[ "$3" = "" ] && echo "No file to read from" && exit 3
|
[ "$3" = "" ] && echo "No file to read from" && exit 3
|
||||||
[ "$2" = "" ] && echo "No chat to send to" && exit 3
|
[ "$2" = "" ] && echo "No chat to send to" && exit 3
|
||||||
while true ;do
|
while read -r -t 10 line ;do
|
||||||
line=""
|
|
||||||
read -r -t 10 line
|
|
||||||
[ "$line" != "" ] && send_message "$2" "$line"
|
[ "$line" != "" ] && send_message "$2" "$line"
|
||||||
done
|
done
|
||||||
rm -f -r "${TMPDIR:-.}/$3"
|
rm -f -r "${TMPDIR:-.}/$3"
|
||||||
|
[ -s "${TMPDIR:-.}/$3.log" ] || rm -f "${TMPDIR:-.}/$3.log"
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
"startbot" )
|
"startbot" )
|
||||||
|
@ -5,7 +5,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$$ v0.80-dev3-0-g31a5d00
|
#### $$VERSION$$ v0.80-dev3-1-gbccd064
|
||||||
|
|
||||||
# adjust your language setting here
|
# adjust your language setting here
|
||||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||||
@ -26,6 +26,7 @@ until [ "$SUCCESS" = "y" ] ;do
|
|||||||
case $answer in
|
case $answer in
|
||||||
'Yass!') echo "Goody! mykeyboardendshere";SUCCESS=y;;
|
'Yass!') echo "Goody! mykeyboardendshere";SUCCESS=y;;
|
||||||
'No') echo "Well that's weird. mykeyboardendshere";SUCCESS=y;;
|
'No') echo "Well that's weird. mykeyboardendshere";SUCCESS=y;;
|
||||||
|
'') echo "empty answer!" && exit;;
|
||||||
*) SUCCESS=n;;
|
*) SUCCESS=n;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
@ -5,7 +5,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$$ v0.80-dev3-0-g31a5d00
|
#### $$VERSION$$ v0.80-dev3-1-gbccd064
|
||||||
|
|
||||||
# source from commands.sh if you want ro use interactive or background jobs
|
# source from commands.sh if you want ro use interactive or background jobs
|
||||||
|
|
||||||
@ -50,8 +50,8 @@ listproc() {
|
|||||||
# $2 program
|
# $2 program
|
||||||
# $3 jobname
|
# $3 jobname
|
||||||
start_back() {
|
start_back() {
|
||||||
local fifo; fifo="$(fifoname "$1")"
|
local fifo; fifo="${TMPDIR:-.}/$(fifoname "$1")"
|
||||||
echo "$1:$3:$2" >"${TMPDIR:-.}/${fifo}$3-back.cmd"
|
echo "$1:$3:$2" >"${fifo}$3-back.cmd"
|
||||||
start_proc "$1" "$2" "back-$3-"
|
start_proc "$1" "$2" "back-$3-"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,9 +62,12 @@ start_back() {
|
|||||||
start_proc() {
|
start_proc() {
|
||||||
[ "$2" = "" ] && return
|
[ "$2" = "" ] && return
|
||||||
kill_proc "$1" "$3"
|
kill_proc "$1" "$3"
|
||||||
local fifo; fifo="$(fifoname "$1" "$3")"
|
local fifo; fifo="${TMPDIR:-.}/$(fifoname "$1" "$3")"
|
||||||
mkfifo "${TMPDIR:-.}/${fifo}"
|
mkfifo "${fifo}"
|
||||||
( $2 <"${TMPDIR:-.}/${fifo}" | "${SCRIPT}" outproc "${1}" "${fifo}"; ) &>>"${TMPDIR:-.}/${fifo}.log" &
|
{ set -f
|
||||||
|
# shellcheck disable=SC2002
|
||||||
|
cat "${fifo}" | $2 | "${SCRIPT}" outproc "${1}" "${fifo}"
|
||||||
|
} &>>"${fifo}.log" &
|
||||||
disown -a
|
disown -a
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,12 +99,14 @@ kill_back() {
|
|||||||
kill_proc() {
|
kill_proc() {
|
||||||
local fifo; fifo="$(fifoname "$1" "$2")"
|
local fifo; fifo="$(fifoname "$1" "$2")"
|
||||||
kill -15 "$(listproc "${fifo}")" 2>/dev/null
|
kill -15 "$(listproc "${fifo}")" 2>/dev/null
|
||||||
rm -f -r "${TMPDIR:-.}/${fifo}";
|
fifo="${TMPDIR:-.}/${fifo}"
|
||||||
|
[ -s "${fifo}.log" ] || rm -f "${fifo}.log"
|
||||||
|
[ -p "${fifo}" ] && rm -f "${fifo}";
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1 chat
|
# $1 chat
|
||||||
# $2 message
|
# $2 message
|
||||||
forward_interactive() {
|
forward_interactive() {
|
||||||
local fifo; fifo="$(fifoname "$1")"
|
local fifo; fifo="${TMPDIR:-.}/$(fifoname "$1")"
|
||||||
[ -p "${fifo}" ] && echo "$2" >"${fifo}"
|
[ -p "${fifo}" ] && echo "$2" >"${fifo}"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user