Home > Software design >  Starting new Screen on the background on reboot
Starting new Screen on the background on reboot

Time:11-19

I have telegram-bot, which I would like to get running every reboot automatically. I've been using Screen to detach this python script manually and leaving it to the background. Before, I have used Screen's commands Ctrl A and D to detach the session.

I've tried to learn some Screen commands, but it doesnt seem to work. Here's what I have so far:

#!/bin/sh
echo
cd "/home/mainuser/Documents/TelegramBot";
sleep 5
python3 telegram_bot.py

And I have set this as command.sh in Documents/LaunchCommands. Then, in my crontab I have:

@reboot screen -S TELEGRAM -X screen /home/mainuser/Documents/LaunchCommands/command.sh

But when I restart my computer, nothing is running. Any help on what might be wrong?? I would love to have the Screen, open new session with name: "TELEGRAM", launch that script in that session and then detach it to the background, so that I can re-attach later if I want. Any ideas? Thank you for your help!

You can also suggest some other ideas, how to get this python script running at the background in a way, that I can still interact with it.

CodePudding user response:

Ok, after looong time debugging, and asking from elsewhere, here's how I got this working:

In crontab, I have line:

@reboot sleep 5; /usr/bin/screen -dmS TELEGRAM /home/mainuser/Documents/LaunchCommands/command.sh &

And my command.sh is as follows:

#!/bin/sh
echo
cd "/home/mainuser/Documents/TelegramBot";
python3 telegram_bot.py

And now everything works like a charm!

  • Related