Advertisement
Guest User

Untitled

a guest
Sep 9th, 2016
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. set -e
  4.  
  5. SITE=$1
  6. if [ "$SITE" = "" ]; then
  7. echo "USAGE: $0 site-shortname <environment>
  8.  
  9. Open a mysql connection to a site via an SSH tunnel.
  10.  
  11. site-shortname: REQUIRED: If your site is dev-example.pantheon.io
  12. this would be \"example\" .
  13.  
  14. environment: Defaults to \"dev\".
  15. "
  16. exit 1
  17. fi
  18.  
  19. ENVIRONMENT=$2
  20. if [ -z "$ENVIRONMENT" ]; then
  21. ENVIRONMENT="dev"
  22. fi
  23.  
  24. if [ "$ENVIRONMENT" != "live" ]; then
  25. echo "Waking up the $SITE site's $ENVIRONMENT environment."
  26. terminus site wake --site="$SITE" --env="$ENVIRONMENT"
  27. fi
  28.  
  29. SFTP_USER=$(terminus site connection-info --site="$SITE" --field=sftp_username --env="$ENVIRONMENT")
  30. MYSQL_PORT=$(terminus site connection-info --site="$SITE" --field=mysql_port --env="$ENVIRONMENT")
  31. MYSQL_PASSWORD=$(terminus site connection-info --site="$SITE" --field=mysql_password --env="$ENVIRONMENT")
  32. MYSQL_HOST=$(terminus site connection-info --site="$SITE" --field=mysql_host --env="$ENVIRONMENT")
  33.  
  34. echo "Setting up the tunnel: ssh -f -N -L $MYSQL_PORT:localhost:$MYSQL_PORT -p 2222 $SFTP_USER@$MYSQL_HOST"
  35. ssh -f -N -L "$MYSQL_PORT":localhost:"$MYSQL_PORT" -p 2222 "$SFTP_USER"@"$MYSQL_HOST"
  36.  
  37. cleanup() {
  38. echo "Killing the tunnel."
  39. pkill -f -U "$(whoami)" "ssh -f -N -L $MYSQL_PORT:"
  40. }
  41. trap cleanup EXIT
  42.  
  43. echo "Connecting to the database."
  44. 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