Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -e
- SITE=$1
- if [ "$SITE" = "" ]; then
- echo "USAGE: $0 site-shortname <environment>
- Open a mysql connection to a site via an SSH tunnel.
- site-shortname: REQUIRED: If your site is dev-example.pantheon.io
- this would be \"example\" .
- environment: Defaults to \"dev\".
- "
- exit 1
- fi
- ENVIRONMENT=$2
- if [ -z "$ENVIRONMENT" ]; then
- ENVIRONMENT="dev"
- fi
- if [ "$ENVIRONMENT" != "live" ]; then
- echo "Waking up the $SITE site's $ENVIRONMENT environment."
- terminus site wake --site="$SITE" --env="$ENVIRONMENT"
- fi
- SFTP_USER=$(terminus site connection-info --site="$SITE" --field=sftp_username --env="$ENVIRONMENT")
- MYSQL_PORT=$(terminus site connection-info --site="$SITE" --field=mysql_port --env="$ENVIRONMENT")
- MYSQL_PASSWORD=$(terminus site connection-info --site="$SITE" --field=mysql_password --env="$ENVIRONMENT")
- MYSQL_HOST=$(terminus site connection-info --site="$SITE" --field=mysql_host --env="$ENVIRONMENT")
- echo "Setting up the tunnel: ssh -f -N -L $MYSQL_PORT:localhost:$MYSQL_PORT -p 2222 $SFTP_USER@$MYSQL_HOST"
- ssh -f -N -L "$MYSQL_PORT":localhost:"$MYSQL_PORT" -p 2222 "$SFTP_USER"@"$MYSQL_HOST"
- cleanup() {
- echo "Killing the tunnel."
- pkill -f -U "$(whoami)" "ssh -f -N -L $MYSQL_PORT:"
- }
- trap cleanup EXIT
- echo "Connecting to the database."
- mysql -A -u pantheon -p"$MYSQL_PASSWORD" -h 127.0.0.1 -P "$MYSQL_PORT" pantheon
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement