Running Python dashboards on a remote machine can feel repetitive: log in via SSH, activate a virtual environment, navigate into the right directory, and finally launch your script. Doing that every time by hand is error-prone. I solved this by writing a Bash script that automates the whole process.
Here’s the (sanitized) version:
!/bin/bash
Example script to start a remote Python dashboard
--- CONFIG ---
REMOTE_USER="username" REMOTE_HOST="xxx.xxx.xxx.xxx" # obfuscated IP REMOTE_PASS="**" # obfuscated password VENV_PATH="~/peakecoin_venv_312/bin/activate" APP_DIR="~/peakecoin/swapbots/uni_bots" APP="dashboard.py"
--- EXECUTE ---
sshpass -p "$REMOTE_PASS" ssh -t -o StrictHostKeyChecking=no ${REMOTE_USER}@${REMOTE_HOST} \ "bash -c 'source $VENV_PATH && cd $APP_DIR && nohup python3 $APP > dashboard.log 2>&1 &'"
How It Works:
- sshpass: lets the script pass credentials non-interactively
- StrictHostKeyChecking=no: avoids prompts on first connection
- source $VENV_PATH: activates the Python virtual environment
- cd $APP_DIR && python3 $APP: navigates to the right folder and starts the dashboard
- nohup … &: keeps it running even after you disconnect
Security Note:
For safety, you should never hard-code passwords or IP addresses in a production script.
A better approach is to store credentials in environment variables ($DASH_PASS, $DASH_IP, etc)
or use SSH keys instead of passwords. That way, you can share your script publicly while
keeping sensitive information private.
With this in place, starting the dashboard remotely is as simple as:
./start_dashboard.sh