Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.81 KB | None | 0 0
  1. !/usr/bin/env ruby
  2.  
  3. require 'socket'
  4. require 'rubygems'
  5. require 'net/ssh'
  6.  
  7. File.open(ARGV[0], "r") do |infile|
  8.     while (line = infile.gets)
  9.         host,username,password,command = line.chomp.split(',')
  10.  
  11.         Thread.new {
  12.             if username == nil || password == nil then
  13.                 puts "#{host}: No username or password, skipping"
  14.                 Thread.exit
  15.             end
  16.  
  17.             begin
  18.                 TCPSocket.new(host, 22)
  19.             rescue
  20.                 puts "#{host}: Unknown host, skipping"
  21.                 Thread.exit
  22.             end
  23.  
  24.             Net::SSH.start( host, username, :password => password) do |ssh|
  25.                 puts "#{host}: #{ssh.exec! command}"
  26.             end
  27.         }
  28.     end
  29.  
  30.     while Thread.list.size > 1 do
  31.        sleep 5
  32.     end
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement