Implement session reminders with .bashrc on Proxmox

I use a small .bashrc tweak on Proxmox SSH logins. It reminds me if I left a screen or tmux session detached, which saves a bit of faff on the hypervisor.

Drop this into ~/.bashrc on the Proxmox host. It only runs for interactive SSH shells, so it stays out of the way for scp and other non-interactive jobs.

if [ -n "$SSH_CONNECTION" ] && [ -t 1 ]; then
  # check GNU Screen
  screen_out=$(screen -ls 2>/dev/null | grep -E 'Detached|Attached' || true)
  if [ -n "$screen_out" ]; then
    echo "Reminder: screen sessions present:"
    echo "$screen_out"
  fi

  # check tmux
  if command -v tmux >/dev/null 2>&1; then
    tmux_out=$(tmux ls 2>/dev/null || true)
    if [ -n "$tmux_out" ]; then
      echo "Reminder: tmux sessions present:"
      echo "$tmux_out"
    fi
  fi
fi

This does three things. It checks for an SSH session with $SSH_CONNECTION. It looks for screen sessions with screen -ls and filters for Attached or Detached. It checks tmux with tmux ls only if tmux is installed. Errors are silenced, so the prompt stays clean if nothing is running.

If you want a sharper reminder, use counts and thresholds. Replace the echo block with a one-liner that only warns when detached sessions exist:

detached_count=$(screen -ls 2>/dev/null | grep -c 'Detached' || echo 0)
if [ "$detached_count" -gt 0 ]; then
  echo "You have $detached_count detached screen session(s). Attach or kill them."
fi

For tmux, parse the tmux ls output for sessions that are not attached. Tmux does not label sessions as Attached or Detached the same way, so a practical check is to count sessions and compare to tmux list-clients if you need per-session attachment details.

A few Proxmox notes from using this on several hypervisors. Keep the check to interactive shells so automation stays quiet. I keep it in .bashrc rather than .profile because Proxmox shells are interactive by default. If you prefer a separate script, call that from .bashrc. If you use SSH multiplexing or jump hosts, the $SSH_CONNECTION test still works for the final hop. tty -s or [ -t 1 ] both do the job for checking a terminal.

If nothing shows up, test the commands by hand: screen -ls and tmux ls. If tmux ls returns “no server running”, there are no sessions. If the checks print errors, add 2>/dev/null to silence them. If the reminder appears on local logins, check that $SSH_CONNECTION is empty locally and only set over SSH. Keep the message short and useful.

That has saved me a bit of cleanup on Proxmox. Simple Bash, a couple of session checks, and fewer forgotten detached shells chewing through the hypervisor.

Related posts

Privacy boundaries when AI touches government records

AI governance gets awkward fast when government records are involved, because the model is rarely the problem. The problem is the sloppy boundary around it, the sort I have seen quietly turn a...

Metadata schema choices for content libraries

Structured metadata only works when it matches how people actually retrieve content. I have seen neat schemas fail as soon as the library meets real records, and tarot makes the problem obvious. If...

Federation trade-offs in self-hosted social feeds

Federation looks tidy until you let it touch the edges, and then the odd cases arrive fast. I prefer self-hosted social feeds that stay explicit about what is local, what is remote, and what should...