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

Immich | v3.3.6

Immich v3 3 6: onnxruntime telemetry disabled in ML container, anonymous metrics stopped, upgrade to v3 3 6 to restore privacy, thanks to the community

Ransomware group fragmentation and detection priorities

Ransomware group fragmentation means the label matters less than the behaviour, and I trust activity over reputation every time. A small crew with rented services can do plenty of damage, so I watch...

k3s | v1.37.2+k3s1

k3s update: upgrades embedded Kubernetes to 1372, bumps core components, backports stability fixes, and improves CI, testing and reproducible builds