From eff4a68c70169bb7e97d6bf4bbfcd179f2220b39 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 24 Mar 2019 19:31:54 +0100 Subject: [PATCH] add example startup/init script and crontab --- bashbot.cron | 32 +++++++++++++++++++++++++ bashbot.rc | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ bashbot.sh | 2 +- 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 bashbot.cron create mode 100755 bashbot.rc diff --git a/bashbot.cron b/bashbot.cron new file mode 100644 index 0000000..485002a --- /dev/null +++ b/bashbot.cron @@ -0,0 +1,32 @@ +# +# this is an exmaple crontab file for telegram-bot-bash +# copy it to /etc/cron.d/bashbot +# +# (c) https://github.com/gnadelwartz +# +# This file is public domain in the USA and all free countries. +# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) + +SHELL=/bin/sh +PATH=/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin: +MAILTO=root # place your mailadress here + + +# ┌───────────── minute (0 - 59) +# │ ┌───────────── hour (0 - 23) +# │ │ ┌───────────── day of the month (1 - 31) +# │ │ │ ┌───────────── month (1 - 12) +# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday; +# │ │ │ │ │ 7 is also Sunday on some systems) +# │ │ │ │ │ +# │ │ │ │ │ +# * * * * * USER command to execute +# * * * * * root echo "run every minute!" + +# run as www every day at 0:00 + 0 0 * * * www /usr/local/telegram-bot-bash/bashbot.sh start # (re)start bot + 0 0 * * * www /usr/local/telegram-bot-bash/bashbot.sh resumeback # (re)start background jobs + +# run as www on 24 of Dec, 12:00 + 0 12 24 12 * www /usr/local/telegram-bot-bash/bashbot.sh broadcast "X-Mas shopping is over!" # broadcast qa message + diff --git a/bashbot.rc b/bashbot.rc new file mode 100755 index 0000000..53d0fb9 --- /dev/null +++ b/bashbot.rc @@ -0,0 +1,67 @@ +#!/bin/sh +# description: Start or stop telegram-bash-bot +# +### BEGIN INIT INFO +# Provides: bashbot +# Required-Start: $network $syslog +# Required-Stop: $network +# Default-Start: 2 3 5 +# Default-Stop: 0 1 6 +# Description: Start or stop telegram-bot-bash server +### END INIT INFO + +runas="root" # not recommended! +runcmd="echo" # not activated until you edit lines below + +# uncomment the next line to run as other user, e.g. www +# runas="www" + +# uncomment one of the following lines +# runcmd="su $runas -s /bin/bash -c " # runasuser with su +# runcmd="runuser $runas -s /bin/bash -c " # runasuser with runuser + +# uncomment and adjust the the values of the following lines +# start="/usr/local/telegram-bot-bash/bashbot.sh" +# lockfile=/usr/local/telegram-bot-bash/lockfile +# name='new-session' # telegram name of your bot + + +case "$1" in +'start') + $runcmd "$start start" # >/dev/null 2>&1 /dev/null 2>&1 + fi + ;; +'stop') + $runcmd "$start kill" + RETVAL=$? + if [ "$RETVAL" = "0" ]; then + rm -f $lockfile + fi + ;; +'status') + ps -f -u $runas | grep "$name" | grep -qF "bashbot.sh startbot" + if [ "$?" = "0" ]; then + echo "$name is running" + RETVAL=0 + else + echo "$name is stopped" + RETVAL=1 + fi + ;; +'restart'|'reload') + $stop ; $start + RETVAL=$? + ;; +'suspendback'|'resumeback'|'killback') + $runcmd "$start $1" + ;; +*) + echo "Usage: $0 { start | stop | restart | reload | suspendback | resumeback | killback }" + RETVAL=1 + ;; +esac +exit $RETVAL + diff --git a/bashbot.sh b/bashbot.sh index 1250e16..0f8f3aa 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -2,7 +2,7 @@ # bashbot, the Telegram bot written in bash. # Written by Drew (@topkecleon) and Daniil Gentili (@danogentili). -# Also contributed: JuanPotato, BigNerd95, TiagoDanin, iicc1. +# Also contributed: JuanPotato, BigNerd95, TiagoDanin, iicc1, Gnadelwartz. # https://github.com/topkecleon/telegram-bot-bash # Depends on JSON.sh (http://github.com/dominictarr/JSON.sh) (MIT/Apache),