2016-11-18 11 views
1

私のスクリプトのsshがHPのスイッチに入っていて、インターフェースを変更します。出力に誤りのある文字が何を引き起こしているのか分かりません(太字参照)。スクリプトに間違った文字があります

マイスクリプト:

#!/usr/bin/expect 
spawn ssh -o StrictHostKeyChecking=no [email protected] 
expect { 
     "password:" { send "passwd\r" ; exp_continue } 
     "Press any key to continue" { send " \r" ; exp_continue } 
     "240#" { send "conf t\r" } 
} 
expect { 
     "(config)#" { send "int 8\r" } 
} 
expect { 
     "(eth-8)#" { send "enable\r" } 
} 
expect { 
     "(eth-8)#" { send "wr mem\r" } 
} 
expect { 
     "(eth-8)#" { send "end\r" } 
} 
expect { 
     "#" { send "logout\r" } 
} 
expect eof 

が誤った出力は、以下を参照してください: ; 209R & 、209R^C

[email protected]:/config/scripts$ ./test_disable.exp 
spawn ssh -o StrictHostKeyChecking=no [email protected] 
========= WARNING: Unauthorized access to this system is forbidden 
and will be prosecuted by law. By accessing this system, you agree 
that your actions may be monitored if unauthorized usage is suspected. 
=== 

[email protected]'s password: 
Press any key to continue 
Your previous successful login (as user) was on 2016-11-18 14:30:54 
from <ip removed> 
swtch-16-57-240# 
swtch-16-57-240# conf t 
swtch-16-57-240(config)# int 8;209R 
swtch-16-57-240(eth-8)# enable 
swtch-16-57-240(eth-8)# wr mem 
swtch-16-57-240(eth-8)# end 
swtch-16-57-240# logout 
Do you want to log out [y/n]? y 
Connection to switch closed by remote host. 
Connection to switch closed. 
[email protected]:/config/scripts$ ;209R^C 
[email protected]:/config/scripts$ 

答えて

1

はそれがマングド制御シーケンスだろうか? Rで終わるだけVT100配列は:

PlPcカーソル位置の行と列数の整数である
Cursor position report  CPR  ESC [ Pl ; Pc R 

http://www.vt100.net/docs/vt102-ug/appendixc.htmlを参照します)。

簡単な解決策は次のようにsshを実行することがあります

set env(TERM) dumb 
spawn env TERM=dumb ssh -o StrictHostKeyChecking=no [email protected] 

をし、難しい方法は何とかエスケープシーケンスを除去が含まれます。 dumbvt100に変更してみてください(現在設定されているものは何ですか?)

+0

「簡単な解決策」は依然として誤った出力を引き起こします。私はストップエスケープseqを調査します。他の入力は感謝しています。 – randydrobinson

+0

expectスクリプト制御シーケンスを送信するとどうなるでしょうか。 'ssh'をlocalhostにコピーし、ルータと同様の出力をエコーし​​、CPRのようなエスケープシーケンスをエコーするスクリプトを実行します。 –

+0

この状況で役に立つかもしれないvttestというプログラムがあります。 –

関連する問題