2016-11-18 2 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

그것이 munged 제어 시퀀스가 ​​될 수 있을까요? R로 끝나는 유일한 VT100 시퀀스는 다음과

Pl Pc 커서 위치의 행 및 열 수의 정수
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

'쉬운 해결책'은 여전히 ​​잘못된 출력을 유발합니다. 나는 스트립 esc seq를 조사 할 것이다. 다른 입력은 감사하겠습니다. – randydrobinson

+0

expect 스크립트 제어 시퀀스를 보내면 어떻게 될지 알아야합니다. 'ssh'를 localhost에 넣고 라우터와 비슷한 결과를 출력하는 스크립트를 실행하고 CPR과 같은 이스케이프 시퀀스를 반영합니다. –

+0

이 상황에서 도움이 될 수있는 vttest라는 프로그램이 있습니다. –

관련 문제