slomg_
slomg_

Reputation: 45

How to auto-start a tmux session on boot, and then run a python file in it (On a Raspberry Pi)

I have a python discord bot, and I want to make it auto start whenever the raspberry pi boots up.

The current way I am making the bot not close whenever I close the ssh session is with tmux.

How do I make the tmux auto-start on boot, and then run a python file in it?

Thank you.

Upvotes: 0

Views: 835

Answers (1)

mattb
mattb

Reputation: 3063

I have this in my .bashrc to launch tmux, and attach to a session I call 'main' (and create if it that session doesn't already exits)

# Launch tmux
if command -v tmux>/dev/null; then
    [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && tmux new-session -A -s main
fi

Then I assume it's not difficult to put a command to run a python file straight after this.

Upvotes: 2

Related Questions