2012-04-26 43 views
1

ruby​​ net-ssh gemを使用してJuniper M10iルータを変更したいと考えています。しかし、 "configure"を送信した後、私は設定コマンドを送ることができません。ruby​​ gem net-sshを使用してJuniperルータを設定する

たとえば、SSH経由でルータにログインした後、私は以下の3つのコマンドを発行したいと思います。net-sshのライブラリを使用して

configure 
show system 
exit 

を、私は成功せず、次の試してみました:

Channel open. 
FAIL: show system 
FAIL: exit 
Data Entering configuration mode 
!!!!!!!!!! 
Channel is closing! 

私が正しくPASんので、どのように:私は次の出力を得ることが実行されると

# net-ssh (2.3.0) 
require 'net/ssh' 

session = Net::SSH.start(host, user, :password => password) 
session.exec!('term length 0') 
session.exec!('term width 0') 

channel = session.open_channel do |ch| 
    puts "Channel open." 

    ch.on_close do |ch| 
    puts "Channel is closing!" 
    end 

    ch.on_data do |ch, data| 
    puts "Data #{data}!!!!!!!!!!" 
    end 

    ch.exec "configure" do |ch, success| 
    puts "FAIL: configure" unless success 
    end 

    ch.exec "show system" do |ch, success| 
    puts "FAIL: show system" unless success 
    end 

    ch.exec "exit" do |ch, success| 
    puts "FAIL: exit" unless success 
    end 
end 
session.loop 

s "configure"の後の "show system"コマンド?

は解決:

を私は次のポストに出くわし:ポストに基づいてhttps://stackoverflow.com/a/6807178/152852

答えて

2

https://stackoverflow.com/a/6807178/152852、追加の宝石 "ネットのssh-Telnetを" 私は正確な動作を提供します探している。

require 'net/ssh' 
require 'net/ssh/telnet' 

session = Net::SSH.start(host, user, :password => password) 
t = Net::SSH::Telnet.new("Session" => session, "Prompt" => prompt) 

puts t.cmd 'configure' 
puts t.cmd 'show | compare' 
puts t.cmd 'exit' 
puts t.cmd 'exit' 
+0

は、 "プロンプト" を指定しないようにとにかくありますか? "プロンプト"を正しく指定しないと、スクリプトがハングします。 –

+0

デフォルトのプロンプトを指定する必要はなく、デフォルトのプロンプトと一致する可能性があります。 –

+0

おかげで、あなたのポストを見るまで、プロンプトとぶら下がっているスクリプトの種類がしばらく私を困惑させました。 +1されました –

1

私は、これは超古い質問です知っているが、参考のために、私は、特にシスコ/ジュニパーのスイッチの自動化のためのラップのTelnet/SSHセッション2つのRubyライブラリ見つけた:のCisco IOS(

関連する問題