#!/bin/bash
if [ "pgrep -f bot.py" != 0 ]
then {
sleep 1 #delay
/usr/bin/python3.6 /home/usertest/bot.py
exit 1
}
else
{
echo "Exit! Python bot is already running!"
exit 1
}
fi;chmod u+x /home/usertest/crontab.shcrontab -e*/5 * * * * /home/usertest/crontab.sh
#!/bin/bash
PIDFILE=/home/usertest/bot.pid
if pgrep --pidfile $PIDFILE &>/dev/null; then
echo "Exit! Python bot is already running!"
exit 1
else
nohup /usr/bin/python3.6 /home/usertest/bot.py &>/dev/null &
echo $!>$PIDFILE
fi #!/bin/bash
PIDFILE=/home/admin/bot-file.pid
if pgrep --pidfile $PIDFILE &>/dev/null; then
echo "Exit! Python bot is already running!"
exit 1
else
nohup /usr/bin/python3.6 /home/admin/bot-file.py &>/home/admin/bot-file.log &
echo $!>$PIDFILE
fi
def sendall(text):
if len(config.users) > 0:
for user in config.users:
try:
bot.send_message(user, text)
except:
print()
...
тело бота с функциями
...
sendall('Бот запущен и готов к работе!')
bot.polling() #!/bin/bash
if pgrep -f "/usr/bin/python3.6 /home/usertest/bot.py" >&/dev/null
then {
echo "Exit! Python bot is already running!"
exit 1
}
else
{
sleep 1 #delay
/usr/bin/python3.6 /home/usertest/bot.py
exit 0
}
fi; if pgrep -f "/usr/bin/python3.6 /home/usertest/bot.py" >&/dev/nullif pgrep -f "/home/usertest/bot.py" >&/dev/null
>/dev/null&>/dev/null
There are two formats for redirecting standard output and standard error:
&>word
and
>&word
Of the two forms, the first is preferred. This is semantically equivalent to
>word 2>&1
When using the second form, word may not expand to a number or ‘-’. If it does, other redirection operators apply (see Duplicating File Descriptors below) for compatibility reasons.