Created
January 21, 2020 16:16
-
-
Save nilsmeyer/ee3902fe2662cb828b8b1015b8bfc96f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
umask 077 | |
if [ "$1" == "" ] | |
then | |
echo "Usage: pg_connect SSH_HOST psql_options" | |
fi | |
ssh_host=$1 | |
shift | |
sessiondir=~/.pgsession/${ssh_host} | |
mkdir -p ${sessiondir} | |
ssh -o StreamLocalBindUnlink=yes -o ControlMaster=auto -o ControlPath=${sessiondir}/.ssh-control -O check -M -f -N -T -L ${sessiondir}/.s.PGSQL.5432:/var/run/postgresql/.s.PGSQL.5432 ${ssh_host} | |
psql -h ${sessiondir} $* | |
netstat -nx | grep "${sessiondir}/.ssh-control" || ssh -o ControlPath=${sessiondir}/.ssh-control -O exit ${ssh_host} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment