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
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"
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 &'"
./start_dashboard.sh