Skip to content

Instantly share code, notes, and snippets.

@santalex
Forked from meeuw/myclic.py
Created September 19, 2017 06:39
Show Gist options
  • Save santalex/4ec942b2fa871a6fa767d8e43c892074 to your computer and use it in GitHub Desktop.
Save santalex/4ec942b2fa871a6fa767d8e43c892074 to your computer and use it in GitHub Desktop.
mycli ssh tunnel script
#!/usr/bin/python
import os
import sys
sshtunnel = None
with open('mysql/'+sys.argv[1]) as f:
s = f.read()
if len(s) > 0 and s[0] == '#':
sshtunnel = s[1:].split('\n')[0]
if sshtunnel and os.system('ssh -O check %s-controlmaster' % sshtunnel) != 0:
os.system('ssh -f %s-controlmaster sleep 60' % sshtunnel)
os.execvp('mycli', ['mycli', '--defaults-file', '/home/meeuw/mysql/'+sys.argv[1], '--prompt', sys.argv[1]+' \d > ']+sys.argv[2:])
Host remotehost-controlmaster
ControlMaster auto
ControlPath /home/meeuw/.ssh/remotehost-socket
HostName remotehost
User user
LocalForward 3306 localhost:3306
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment