The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
SSH Util Ruby Script

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Joey Gibson

Posts: 71
Nickname: joeygibson
Registered: Jun, 2003

Joey Gibson is an opinionated software architect who blogs about technology, politics, music, etc.
SSH Util Ruby Script Posted: Jan 7, 2004 8:38 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Joey Gibson.
Original Post: SSH Util Ruby Script
Feed Title: Joey Gibson's Blog
Feed URL: http://www.jobkabob.com/index.html
Feed Description: Thoughts, musings, ramblings and rants on Java, Ruby, Python, obscure languages, politics and other exciting topics.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Joey Gibson
Latest Posts From Joey Gibson's Blog

Advertisement
OpenSSH, that ships with Cygwin has a nice utility called ssh-agent. This program is a daemon that will hold on to your keys so that hosts you are authorized to log on to will not continually ask for your password. This is especially useful when working with CVS repositories over SSH. When you run ssh-agent, it spits out text that should be evaluated to set two environment variables that you will need in order to run ssh-add, to actually add your keys to it. That output looks like this:
SSH_AUTH_SOCK=/tmp/ssh-mjKjm512/agent.512; export SSH_AUTH_SOCK;
SSH_AGENT_PID=1600; export SSH_AGENT_PID;
echo Agent pid 1600;
On a Unix system, it's easy to capture the output of ssh-agent and evaluate it, but under the 'command shell' that ships with Windows systems, which is so patheticly crippled that my old Commodore 64's BASIC-based shell is looking pretty good, you can't do that.

So what are those poor saps, myself included, who are using Windows systems to do? Ruby to the rescue. I wrote a simple script that executes ssh-agent, capturing the output, massaging it a little, and then creating a batch file that I can run to set the necessary variables. Simply redirecting the output to a batch file won't work because there are some Unix-isms, such as exporting the variables, that don't work on Windows. So, here's the script:
 1  #!ruby
 2
 3  lines = %x{ssh-agent}
 4
 5  File.open("c:/tmp/sde.bat", "w") do |file|
 6      lines.each do |line|
 7          chunks = line.chomp.split ';'
 8
 9          if<
1000
;/b> chunks[0] =~ /^SSH/
10              file.puts "SET #{chunks[0]}"
11          end
12      end
13  end
You can see that the script sends the captured and massaged output to a batch file called "sde.bat" located in C:/tmp. You can change both of these to suit your preference. Once the script runs, I simply execute the generated batch file and then run ssh-add. The nice thing about the generated batch file is that it lingers until the next time I run the Ruby script. Thus as I open new console Windows I can re-run it to get the environment variables set properly in each one.

Read: SSH Util Ruby Script

Topic: RubyConf, here I come Previous Topic   Next Topic Topic: Deleting Code

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use