3

On startup, I want to have a new tmux session created which inside of that session changes directory and executes a bash script. How do I do this?

Cheers,

Tom

tdubz
  • 41
  • 3
  • 5
  • Are you aware of `cron`? – Nmath Oct 22 '20 at 17:16
  • Yeah I am, but I do not know how to run commands on a new tmux session and schedule it for startup. – tdubz Oct 22 '20 at 17:29
  • 1
    Does this answer your question? [How to run scripts on start up?](https://askubuntu.com/questions/814/how-to-run-scripts-on-start-up) and [How do I start applications automatically on login?](https://askubuntu.com/questions/48321/how-do-i-start-applications-automatically-on-login) – Nmath Oct 22 '20 at 18:02

1 Answers1

4

Create the following script, but adjust it to your needs:

#!/bin/bash

# Create a new session named "newsess" and run a command inside the session
tmux new-session -d -s newsess
tmux send-keys -t newsess "./path/to/myscript" Enter
# Attach to session named "newsess"
tmux attach -t newsess
  • newsess is the name of the session
  • ./path/to/myscript is the full path of the script you want to run inside tmux.

Use any of the methods described here to run the above script on startup.

Artur Meinild
  • 21,605
  • 21
  • 56
  • 89