Auto-launch a tmux monitoring dashboard on Raspberry Pi boot (headless/CLI). Press any key within 10 seconds to skip and drop to shell.
Note
I use this for a pi that I carry on-site, either when I'm teaching or on a client side, where I need a MQTT broker and also where wifi setup shoudl be easy (So, my pi is running: headless pi wifi configurator)
Note
If you are interested in the 3D printed parts, you can find them here in printables
┌─────────────┬─────────────┐
│ app log │ │
│ (tail -f) │ htop │
├─────────────┤ (full right)│
│ mosquitto │ │
│ log │ │
└─────────────┴─────────────┘
- Raspberry Pi OS (headless/CLI)
- tmux
- htop
- mosquitto MQTT broker - as I'm interetsed in showing the logs from the broker as I would be using thsi as a test portable broker
- (logs pane): showing the logs from this project which is a headless pi wifi configurator
1. Create the boot script:
sudo nano /home/pi/rpi-dashboard-boot.shPaste the script below, then:
sudo chmod +x /home/pi/rpi-dashboard-boot.shThen, test it by running manually:
./rpi-dashboard-boot.sh2. Add to shell config (choose your shell):
nano ~/.config/fish/config.fishAdd at the end:
# Auto-launch dashboard on TTY login
if status is-login; and status is-interactive; and test -z "$TMUX"; and tty | grep -q tty
/home/pi/rpi-dashboard-boot.sh
endnano ~/.bash_profileAdd at the end:
# Auto-launch dashboard on TTY login
if [[ -z "$TMUX" ]] && [[ $(tty) == /dev/tty* ]]; then
/home/pi/rpi-dashboard-boot.sh
finano ~/.zprofileAdd at the end:
# Auto-launch dashboard on TTY login
if [[ -z "$TMUX" ]] && [[ $(tty) == /dev/tty* ]]; then
/home/pi/rpi-dashboard-boot.sh
fi3. Reboot and enjoy.
#!/bin/bash
# rpi-dashboard-boot.sh
TIMEOUT=10
SESSION=dashboard
LOG_DIR="/home/pi/rpi-wifi-configurator/logs"
# Countdown with keypress detection
echo ""
echo "╔════════════════════════════════════════════════════════════╗"
echo "║ Press any key within ${TIMEOUT} seconds to skip dashboard... ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo ""
for i in $(seq $TIMEOUT -1 1); do
printf "\r Launching dashboard in %2d seconds... " "$i"
read -t 1 -n 1 key
if [ $? -eq 0 ]; then
echo ""
echo "Key pressed! Dropping to shell..."
exit 0
fi
done
echo ""
echo "Starting dashboard..."
# Kill existing session
tmux kill-session -t $SESSION 2>/dev/null
# Find latest log file
LATEST_LOG=$(ls -t "$LOG_DIR"/log_*.log 2>/dev/null | head -n 1)
if [ -z "$LATEST_LOG" ]; then
LOG_CMD="echo 'No log files found'; $SHELL"
else
LOG_CMD="tail -f '$LATEST_LOG'"
fi
# Create tmux session with 3 panes
tmux new-session -d -s $SESSION
tmux split-window -h -t $SESSION
tmux split-window -v -t $SESSION:0.0
# Pane 0: app log (top-left)
# Pane 1: mosquitto (bottom-left)
# Pane 2: htop (full right)
tmux send-keys -t $SESSION:0.0 "$LOG_CMD" C-m
tmux send-keys -t $SESSION:0.1 'sudo tail -f /var/log/mosquitto/mosquitto.log' C-m
tmux send-keys -t $SESSION:0.2 'htop' C-m
tmux select-pane -t $SESSION:0.0
exec tmux attach-session -t $SESSION| Variable | Description |
|---|---|
TIMEOUT |
Seconds to wait for keypress (default: 10) |
SESSION |
tmux session name |
LOG_DIR |
Directory containing app log files |
- Assumes user is
pi(If not you can always change it, it's a simple script) - Also you can adjust to view what-ever, now you have a boilerplate ...
- Only triggers on TTY (physical console), not SSH sessions. SSH access always drops straight to shell
- Press any key during countdown to skip dashboard
- Kill: You can login to a different session (over SSH) and execute:
tmux kill-session -t dashboardor if you have keyboard attached to the pi, you know what you can do :)
