-
-
Save Abukamel/9681881 to your computer and use it in GitHub Desktop.
fast ssh using farbic and storm
This file contains hidden or 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
#!/usr/bin/python2 | |
# require fabric python module | |
# install pip, then: pip install fabric | |
import sys | |
import subprocess | |
from fabric.api import * | |
try: | |
sys.argv[1] | |
except: | |
sys.exit(1) | |
env.use_ssh_config = True | |
if subprocess.Popen("storm search %s| grep -v Listing| grep -Ev '^$'" % sys.argv[1], shell=True, stdout=subprocess.PIPE).communicate()[0].strip().startswith('no'): | |
print 'Not found.' | |
sys.exit(1) | |
elif subprocess.Popen("storm search %s| grep -v Listing| grep -Ev '^$' | wc -l" % sys.argv[1], shell=True, stdout=subprocess.PIPE).communicate()[0].strip() == '1': | |
env.host_string = '%s' % subprocess.Popen("storm search %s| grep -v Listing| grep -Ev '^$'" % sys.argv[1], shell=True, stdout=subprocess.PIPE).communicate()[0].split()[0] | |
local('ssh %s' % env.host_string) | |
else: | |
for num, server in enumerate([x for x in subprocess.Popen("storm search %s| grep -v Listing| grep -Ev '^$'" % sys.argv[1], shell=True, stdout=subprocess.PIPE).communicate()[0].replace('->', '').split() if not x[-1].isdigit()]): | |
print '%s- %s' % (num, server) | |
choosen = prompt("Choose server number:") | |
for num, server in enumerate([x for x in subprocess.Popen("storm search %s| grep -v Listing| grep -Ev '^$'" % sys.argv[1], shell=True, stdout=subprocess.PIPE).communicate()[0].replace('->', '').split() if not x[-1].isdigit()]): | |
if num == int(choosen): | |
env.host_string = server | |
local('ssh %s' % env.host_string) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment