mysql ssh tunnel (then kill PID)


/ Published in: Bash
Save to your folder(s)



Copy this code and paste it in your HTML
  1. PRODUCTION_PORT=33006
  2. PRODUCTION_SERVER_AUTH=root@0.0.0.0.0
  3.  
  4. #connect to the tunnel and put the connection to the background
  5. ssh -f -N -L $PRODUCTION_PORT:localhost:3306 $PRODUCTION_SERVER_AUTH
  6.  
  7. ...
  8. (do some mysql work by connecting to localhost)
  9. ...
  10.  
  11. #Find the PID of the ssh tunnel in the background and assign it to a variable
  12. PID=$(ps -eo pid,args | grep 'ssh -f -N -L 33006:localhost' | grep -v 'grep' | cut -c1-6)
  13.  
  14. #kill the tunnel
  15. kill -9 $PID

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.