I'm trying to find a way to have tmux start for a specific user on boot. The tmux session should run two Python scripts.

I think I could start Python as mentioned here, but I'd rather have it in a tmux session.

Is that possible and how could I accomplish that?

  • 1
    Most cron implementations has a @reboot tag to run jobs on boot. – Kusalananda May 13 '18 at 16:05

In my case, I have a user account just for the purpose of running one single script, so I provide a default tmux configuration in that user's home directory by creating a file ~/.tmux.conf

My ~/.tmux.conf file looks (roughly) like this:

new-session -d -s MYSESSIONNAME
set -g status off
new-window ~/my-startup-script.sh

my-startup-script.sh needs to have the +x permission set, obviously.

To start the ~/.tmux.conf tmux script, issue the command

tmux start-server

On a system where cron @reboot runs too early in the boot sequence, I run a shell script of the pattern

source ~/.bash_profile
if tmux has-session -t auto-session > /dev/null 2>&1; then
    tmux new-session -d -s auto-session -n foo bar
    tmux new-window -d -t auto-session

regularly every few minutes via crontab

*/2 * * * * $HOME/path/to/start-user-auto-session.bash

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.