>_ IzzyLab

Hands-on task

This task is step 6 of the course “tmux: sessions you never lose”

Send a command into a session

medium~7 min

A demo web server has to survive a dropped SSH connection, so it's started inside tmux. Create a background tmux session w and, without attaching to it, make its shell run the command python3 -m http.server 80 --directory /srv/demo — that is, "type" the command into the session from the outside. The server must run inside the session w itself. See the result in the Site tab above the terminal.

What you'll practise:
  • tmux
  • send-keys
  • automation
  • background sessions

Topic breakdown

tmux lets you control a session from the outside without attaching to it: you can programmatically "type" characters into its shell as if a user entered them. The key detail — the typed text won't run on its own, you need to separately send an Enter keypress (a newline), otherwise the command just hangs in the input line. Execution happens asynchronously in the background shell, so it's worth checking the result with a small delay.

What's checked

  1. session w is running
  2. the site answers with the demo page
  3. the web server runs inside session w

What it looks like