To Create A Session
tmux new-session -s turnip
tmux new-session -d -s cityscape # start detached
To Create A Window
tmux new-window -n <new-window-name> -t <session-name> <cmd>
tmux new-window -n <new-window-name> -t <session-name>:<window-number> <cmd>
Explicit Window Number
To avoid the
create window failed: index 2 in use
error use an explicit window number:
tmux new-window -n <new-window-name> -t <session-name>:<n> <cmd>
Example
This is a random script from my pi3 which starts up some services written in Python.
- One receives UDP packets and sends wakeonlan packets (I haven't succeeded sending them from Windows machines via command line tools, so resorted to sending UDP to my pi3).
- One provides a HTTP interface for sending Wakeonlan packets. This enables me to wake devices from my mobile via a web browser. It also, for Linux targets, allows to sleep and shutdown via ssh.
- The other is a process which manages multiple mpd (Music Player Daemon) instances around my LAN.
This script is a
@rebootentry in my pi3's crontab.
#!/bin/bash
start_wol_all() {
(
cd ~/wol
tmux new-session -d -s wol
sleep 1
tmux new-window -n mpdmgr_http -t wol:1 p mpdmgr_http.py
sleep 1
tmux new-window -n wolsrv_http -t wol:2 p wolsrv_http.py
sleep 1
tmux new-window -n wolsrv -t wol:3 p wolsrv.py
)
}
start_wol_all