Skip to content
SimpleSsh is a simple wrapper around the net-ssh gem.
Ruby
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
.gitignore
CHANGELOG.rdoc
LICENSE
Manifest.txt
README.rdoc
Rakefile

README.rdoc

SimpleSSH

home

github.com/szuecs/simple_ssh

DESCRIPTION

simple_ssh is a simple wrapper around the net-ssh gem.

  • You want to execute a list of commands on a list of hosts using ssh?

  • You want to analyze the results within a script?

If your answers for these questions are yes then simple_ssh is for you.

Examples

Configuration

  • Simple configuration of command list execution by hosts using a block.

    ssh = SimpleSsh::SimpleSSH.configure do |cfg|
      cfg.user = "root"
      cfg.hosts << "192.168.143.153"
      cfg.cmds  << "whoami"
      cfg.cmds  << "id"
      cfg.keys  << "~/.ssh/id_rsa"
    end
    ssh.execute #=> {"192.168.143.153"=>{"whoami"=>"root", "id"=>"uid=0(root) gid=0(root) groups=0(root)"}}
    puts ssh
    #192.168.143.153:
    #        whoami: root
    #        id: uid=0(root) gid=0(root) groups=0(root)
  • Configuration by dictionary or block or both

    ssh = SimpleSsh::SimpleSSH.configure(:cmds => ["hostname"], :user => "root") do |cfg|
      cfg.hosts << "192.168.143.153"
      cfg.cmds  << "whoami"
      cfg.keys  << "~/.ssh/id_rsa"
    end

Command execution

  • Execute the configured hosts and commands

    ssh.execute
  • Execute a block

    ssh.execute do |ch|
      ch.cmds << "echo yeaha"
      ch.cmds << "echo yeaha | openssl dgst -sha1"
    end

Using results

  • Get results by hosts dictionary

    ssh.result_by_host["192.168.143.153"] #=> {"hostname"=>"foreman-squeeze", "whoami"=>"root"}
  • Get results by cmd dictionary

    ssh.result_by_cmd["whoami"] #=> {"192.168.143.153"=>"root"}
  • Dump yaml

    ssh.to_yaml #=> "--- \n192.168.143.153: \n  hostname: foreman-squeeze\n  whoami: root\n"
  • Dump csv

    ssh.to_csv(";") #=> "host;cmd;result\n192.168.143.153;hostname;foreman-squeeze\n192.168.143.153;whoami;root"

REQUIREMENTS

  • net-ssh

INSTALL

% sudo gem install simple_ssh

AUTHORS

Sandor Szücs, sandor.szuecs@fu-berlin.de

LICENSE

See LICENSE file.

Something went wrong with that request. Please try again.