script

You are currently browsing articles tagged script.

With dozens of ssh connections each days, you better need a shortcut way to make it faster. Frustation comes to a end with this script:

#!/usr/bin/env ruby -wKU

servers = [
    {:id => 0, :alias => "aiko", :ip => "server_ip", :login => "ssh_login", :port => "ssh_port"}
  ]

# Read from command line
server_id = ARGV[0].to_i if !ARGV[0].nil?

# Read from input
if server_id.nil?
   servers.each do |server|
     puts "[#{server[:id]}] #{server[:alias]}"
   end
   server_id = gets
end

server_id = server_id.to_i

puts "Connecting to #{servers[server_id][:login]}@#{servers[server_id][:ip]} port #{servers[server_id][:port]}"

exec "ssh #{servers[server_id][:login]}@#{servers[server_id][:ip]} -p #{servers[server_id][:port]}"

Put this ruby script in your bin directory, make it executable, add your servers info hash in the array, and eventually copy your ssh public key in the various servers to never be asked for password.

When executing it, you can give it the ‘id‘ as an argument, and it will connect automatically to the server with the corresponding id!

Tags: , , ,