Skip to content

Instantly share code, notes, and snippets.

@cmittendorf
Created November 11, 2015 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmittendorf/53e9ea0d835faa156228 to your computer and use it in GitHub Desktop.
Save cmittendorf/53e9ea0d835faa156228 to your computer and use it in GitHub Desktop.
Open all AWS EC2 instances of a specific server group using csshX from the current AWS console page in Safari.
set serversList to {}
set serverGroups to {"MyGroup1", "MyGroup2", "MyGroup3"}
set alertTitle to "Open AWS Servers with SSH"
on openServers(servers)
set csshx to "/usr/local/bin/csshX -y 4 --slave_settings_set CSSHX --ssh_args \"-oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null\" "
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set command to (csshx & servers as text) & " &"
get do shell script command
set AppleScript's text item delimiters to saveTID
end openServers
set serverGroupName to missing value
set result to choose from list serverGroups with title alertTitle with prompt "Server Group:" default items {} without multiple selections allowed
if result is false then
return
else
set serverGroupName to item 1 of result
end if
try
tell application "Safari"
tell current tab of front window
if URL contains "console.aws.amazon.com" then
set jsCommand to "re = /" & serverGroupName & "i.*? (ec2.*?\\.amazonaws\\.com)/g; aa = []; res = []; while((res = re.exec(document.body.textContent)) !== null) { aa.push(res[1]); }; aa;"
set serversList to get do JavaScript jsCommand
end if
end tell
end tell
end try
if number of items of serversList is not 0 then
set adminServersList to {}
repeat with server in serversList
set adminServersList to adminServersList & {"admin@" & server}
end repeat
openServers(adminServersList)
tell application "Terminal"
activate
end tell
else
display dialog "No AWS Servers found!" with title alertTitle buttons {"Ok"} default button 1 giving up after 10
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment