bro
#!/usr/bin/env bash
# -----------------------------------------------------------------------------Usage: ./group_by_date_hour_symbol_source.sh path_to_logfile
LOGFILE="$1"
awk '
{
# Configuration# -----------------------------------------------------------------------------# Username and host/IP forSplit the jumpfirst field (bastion) serverJUMP_USER="jumpuser"JUMP_HOST="jump.example.com"
# Username and host/IP for the final remote serverREMOTE_USER="remoteuser"REMOTE_HOST="192.168.1.100"REMOTE_DIR="/path/on/remote/server/myproject"
# Which Python do we use20250209-13:45:02.123456) on the remote?dash.
# dt[1] will hold "20250209", dt[2] will hold "13:45:02.123456".
split($1, dt, "-")
date_str = dt[1] # e.g. python3.9REMOTE_PYTHON="python3.9"
# -----------------------------------------------------------------------------# 1) Prepare offline wheelhouse locally# -----------------------------------------------------------------------------echo "[Local] Creating/updating offline wheelhouse..."pip freeze > requirements.txtmkdir -p packagespip download -r requirements.txt -d packages
# -----------------------------------------------------------------------------# 2) Package the project for deployment# -----------------------------------------------------------------------------echo "[Local] Packaging project..."tar czf myproject.tar.gz \ --exclude=".venv" \ --exclude="myproject.tar.gz" \ --exclude="deploy.sh" \ . # everything else in the current directory
# -----------------------------------------------------------------------------# 3) Secure copy the tarball to remote (via jump server)# -----------------------------------------------------------------------------echo "[Local] Copying archive to remote server via jump..."scp -o ProxyJump="${JUMP_USER}@${JUMP_HOST}" \ myproject.tar.gz \ "${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_DIR}"
# -----------------------------------------------------------------------------# 4) SSH into the remote server (via jump), unpack, create fresh venv, install# -----------------------------------------------------------------------------echo "[Local] Deploying on remote server..."ssh -J "${JUMP_USER}@${JUMP_HOST}" "${REMOTE_USER}@${REMOTE_HOST}" << EOF set -e # Exit on any error20250209"
echo# Now split dt[2] ("[Remote]13:45:02.123456") Enteringon \$HOMEthe /colon \$(pwd)."to get the hour.
cdsplit(dt[2], time_parts, "${REMOTE_DIR}:")
hour = echotime_parts[1] # e.g. "[Remote] Extracting myproject.tar.gz..." tar xzf myproject.tar.gz13"
echosymbol = $2 # e.g. "[Remote] Creating fresh virtual environment..."USDCAD"
source = ${REMOTE_PYTHON}3 -m# venve.g. .venv"MyLiquidityProvider"
echo# Increment a count in an associative array, keyed by date, hour, symbol, source.
counts[date_str, hour, symbol, source]++
}
END {
# Print header (optional)
# print "[Remote]DATE", Activating"HOUR", virtual"SYMBOL", environment"SOURCE", and"COUNT"
packages. # Loop over all keys in counts.
for (key in counts) {
# The key format is "date_str SUBSEP hour SUBSEP symbol SUBSEP source".."
split(key, parts, SUBSEP)
date_str = parts[1]
hour = parts[2]
symbol = parts[3]
source .venv/bin/activate= parts[4]
pipcount install= --upgrade pip pip install --no-index --find-links=packages -r requirements.txtcounts[key]
echoprint date_str, hour, symbol, source, count
}
}
' "[Remote]$LOGFILE" Deployment| complete!"EOF
echo "[Local] Done!"sort