Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: KINGSABRI on Aug 30th, 2012  |  syntax: Ruby  |  size: 1.64 KB  |  views: 47  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.       channel.on_data do |ch1, data|
  20.  
  21.         commands.each do |cmd|
  22.           channel.send_data(cmd + "\n")
  23.           puts data
  24.         end
  25.  
  26.       end
  27.  
  28.       puts channel.exec("sudo bash")
  29.  
  30.     end # end of pty
  31.  
  32.   end   # end of channel
  33.  
  34.   ssh.loop 0.1
  35. end
  36.  
  37.  
  38. #]0;root@pdbosl02:~
  39. #]0;root@pdbosl02:~
  40. #]0;root@pdbosl02:~
  41. #]0;root@pdbosl02:~
  42. #
  43. #
  44. #
  45. #
  46. #[root@pdbosl02 ~]#
  47. #[root@pdbosl02 ~]#
  48. #[root@pdbosl02 ~]#
  49. #[root@pdbosl02 ~]#
  50. #]0;root@pdbosl02:/tmp
  51. #]0;root@pdbosl02:/tmp
  52. #]0;root@pdbosl02:/tmp
  53. #]0;root@pdbosl02:/tmp
  54. #
  55. #
  56. #
  57. #
  58. #[root@pdbosl02 tmp]#
  59. #[root@pdbosl02 tmp]#
  60. #[root@pdbosl02 tmp]#
  61. #[root@pdbosl02 tmp]#
  62. #/tmp
  63. #/tmp
  64. #/tmp
  65. #/tmp
  66. #]0;root@pdbosl02:/tmp
  67. #]0;root@pdbosl02:/tmp
  68. #]0;root@pdbosl02:/tmp
  69. #]0;root@pdbosl02:/tmp
  70. #
  71. #
  72. #
  73. #
  74. #[root@pdbosl02 tmp]#
  75. #[root@pdbosl02 tmp]#
  76. #[root@pdbosl02 tmp]#
  77. #[root@pdbosl02 tmp]#
  78. #]0;root@pdbosl02:/tmp
  79. #]0;root@pdbosl02:/tmp
  80. #]0;root@pdbosl02:/tmp
  81. #]0;root@pdbosl02:/tmp
  82. #
  83. #
  84. #
  85. #
  86. #[root@pdbosl02 tmp]#
  87. #[root@pdbosl02 tmp]#
  88. #[root@pdbosl02 tmp]#
  89. #[root@pdbosl02 tmp]#
  90. #Ruby
  91. #Ruby
  92. #Ruby
  93. #Ruby
  94. #]0;root@pdbosl02:/tmp
  95. #]0;root@pdbosl02:/tmp
  96. #]0;root@pdbosl02:/tmp
  97. #]0;root@pdbosl02:/tmp