I have a bash script that continuously outputs some information when run. I need to

  1. Automatically run this when my system boots.
  2. Monitor this output and control it every once in a while remotely, using ssh.

For this purpose, I would like to use tmux. So how do I approach this? For simplicity, let's say my shell script is this:

filename: start.bash

# just an example for simplicity    
watch date

I need another script that runs this in tmux and be able to attach to this when I need, later. I am struggling at the part where I need to create a new tmux session with a name and make it run another shell script. Once I have this working, I can put this in another shell script and take care of the rest of the stuff. That is easy, I think. Can someone give me an example for this specific step please?


2 Answers 2


You can do this many ways.

You can do it after you've created the session either with send-keys:

tmux new -s "remote" -d
tmux send-keys -t "remote" "start.bash" C-m
tmux attach -t "remote" -d

Or through the shell:

tmux new -s "remote" -d "/bin/bash"
tmux run-shell -t "remote:0" "start.bash"
tmux attach -t "remote" -d

Start a tmux session on the server and do not close it. It will keep running on the server. From your client computer you will be able to ssh in and run

tmux attach

to reconnect to whatever you had running in the tmux session. To start it at boot time if you reboot the server start tmux from a shell script that runs from /etc/rc.local

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .