Ruby 路由器备份脚本

Ruby 路由器备份脚本,ruby,cisco,Ruby,Cisco,我有下面的代码,连接到我的路由器刚刚好。问题是,一旦连接,我会尝试传递“shver”命令,而该命令永远不会传递到路由器。谢谢你的帮助 需要“网络/远程登录” cisco = '1.1.1.1' #Enter the IP address here user = 'admin' #Enter username here pass = 'mypass' #Enter password here tn = Net::Telnet::new('Host' => cisco, 'prompt' =

我有下面的代码,连接到我的路由器刚刚好。问题是,一旦连接,我会尝试传递“shver”命令,而该命令永远不会传递到路由器。谢谢你的帮助

需要“网络/远程登录”

cisco = '1.1.1.1' #Enter the IP address here
user = 'admin' #Enter username here
pass = 'mypass' #Enter password here

tn = Net::Telnet::new('Host' => cisco, 'prompt' => /^\Username:/ )
tn.cmd('String'=>'admin', 'Match'=>/Password:/) { |c| puts c }
tn.cmd(pass) { |c| puts c }

------------------Does not work below this line---------------------
tn.cmd('String'=>'sh ver')

问题是您将“prompt”设置为与Username匹配的表达式:(注意:此处有一个反斜杠,因此它可能实际上与SERNAME:匹配)

因此,当您执行tn.cmd(pass)时,它会发送密码,然后等待Username:(或SERNAME:)


将“prompt”更改为与cisco的常见提示(成功登录后看到的提示)匹配的正则表达式。

因此,这是我根据您的建议使用的代码,它可以正常工作。谢谢

需要“网络/远程登录”

cisco = '1.1.1.1' #Enter the IP address here
user = 'admin' #Enter username here
pass = 'mypass' #Enter password here

tn = Net::Telnet::new('Host' => cisco, 'prompt' => /^\Username:/ )
tn.cmd('String'=>'admin', 'Match'=>/Password:/) { |c| puts c }
tn.cmd(pass) { |c| puts c }

------------------Does not work below this line---------------------
tn.cmd('String'=>'sh ver')
tn=Net::Telnet::new(“主机”=>“1.1.1.1”, “超时”=>10000, “提示”=>/[$%\>]\z/n)

tn.cmd('String'=>'admin','Match'=>/Password:/){c} tn.cmd('String'=>'pass','Match'=>/#/){| c | put c} tn.cmd('String'=>'terminal length 0','Match'=>/#/){c} tn.cmd('String'=>'sh run','Match'=>/#/){c}
tn.close

我要补充一点,他可能想使用waitfor作为初始用户名提示。