Last active
February 10, 2017 15:16
-
-
Save nonplus/c82071213227321b6c1201369bc618bd to your computer and use it in GitHub Desktop.
Scrapes an AWS EC2 instance page and copies the ssh login command to the clipboard
This file contains 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
// Configure the pemDir value (or make empty for current directory) and generate a bookmarklet (http://bookmarklets.org/maker/) | |
// Use the bookmarklet in the AWS dashboard on an EC2 instance page | |
// Paste into terminal shell | |
// Voila! | |
var pemDir = '/path/to/directory/with/pem/files/'; | |
var elts = document.getElementsByTagName("DIV"); | |
var dns = valueOf('Public DNS (IPv4)'); | |
if (!dns) { return; } | |
var keyPair = valueOf('Key pair name'); | |
if (!keyPair) { return; } | |
var cb = document.createElement('TEXTAREA'); | |
var cmd = 'ssh -i "' + pemDir + keyPair + '.pem" ec2-user@' + dns; | |
cb.value = cmd; | |
document.body.appendChild(cb); | |
cb.select(); | |
document.execCommand('copy'); | |
document.body.removeChild(cb); | |
// Key pair name | |
function valueOf(name) { | |
var labelElt = [].find.call(elts, function (e) { return e.innerText === name; }); | |
if (!labelElt) { | |
console && console.error('Could not find "' + name + '" label'); | |
return undefined; | |
} | |
var valueElt = labelElt.nextSibling; | |
if (!valueElt) { | |
console && console.error('Could not find "' + name + '" value'); | |
return undefined; | |
} | |
var value = valueElt.innerText; | |
console && console.info(name + ': ' + value); | |
return value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment