Advertisement
KINGSABRI

Untitled

Aug 30th, 2012
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.29 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. require 'rubygems'
  4. require 'net/ssh'
  5.  
  6. host = "10.20.30.45"
  7. user = "king"
  8. pass = "Badp@ssw0rd"
  9.  
  10. commands = ["cd /tmp/" , "pwd" , "echo 'Ruby' > ruby.txt" , "cat ruby.txt"]
  11.  
  12.  
  13. Net::SSH.start(host, user , :password => pass , :port => 15000 , :timeout => 7 ) do |ssh|
  14.  
  15.   ssh.open_channel(type="session") do |channel|
  16.    
  17.     channel.request_pty(:modes => { Net::SSH::Connection::Term::ECHO => 0 }) do |pty, success|
  18.  
  19.  
  20.       commands.each do |cmd|
  21.  
  22.       channel.on_data do |ch1, data|
  23.        puts "Command is: #{cmd}"
  24.           channel.send_data(cmd + "\n")
  25.           sleep 0.3
  26.           puts data
  27.         end
  28.  
  29.       end
  30.  
  31.       puts channel.exec("sudo bash")
  32.  
  33.     end # end of pty
  34.  
  35.   end   # end of channel
  36.  
  37.   ssh.loop 0.1
  38. end
  39.  
  40.  
  41. #Command is: cat ruby.txt
  42. #]0;root@pdbosl02:~
  43. #Command is: cat ruby.txt
  44. #
  45. #Command is: cat ruby.txt
  46. #[root@pdbosl02 ~]#
  47. #Command is: cat ruby.txt
  48. #cat: ruby.txt: No such file or directory
  49. #]0;root@pdbosl02:~
  50. #Command is: cat ruby.txt
  51. #[root@pdbosl02 ~]#
  52. #Command is: cat ruby.txt
  53. #cat: ruby.txt
  54. #Command is: cat ruby.txt
  55. #: No such file or directory
  56. #Command is: cat ruby.txt
  57. #]0;root@pdbosl02:~
  58. #Command is: cat ruby.txt
  59. #
  60. #Command is: cat ruby.txt
  61. #[root@pdbosl02 ~]#
  62. #Command is: cat ruby.txt
  63. #cat: ruby.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement