Created
March 31, 2015 23:14
-
-
Save mjc/1aac06cfae1ad9ac9e98 to your computer and use it in GitHub Desktop.
export users and hostnames to ssh_config format
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
#!/usr/bin/env ruby | |
require 'pathname' | |
path = Pathname.new(ENV['HOME']).join("Library","Application Support","VanDyke","SecureCRT","Config”,”Sessions”,”**.ini") | |
paths = Dir.glob(path) | |
paths.each do |path| | |
lines = File.readlines(path) | |
hostname = nil | |
username = nil | |
lines.each do |line| | |
result = line.match(/S:"(.+)"=(.+)/) | |
next unless result | |
case result[1] | |
when "Username" | |
username = result[2] | |
when "Hostname" | |
hostname = result[2] | |
end | |
end | |
next unless hostname && username | |
puts "Host %s" % hostname | |
puts "HostName %s" % hostname | |
puts "User %s" % username | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment