2016-07-22 1 views
2

ssh에 사용할 스크립트가 있습니다. 내 호스트 중 일부는 RSA 호스트 키 텍스트로 프롬프트하고 일부는 표시하지 않습니다. if/then을 위해 스크립트를 설치하려면 어떻게해야합니까? 여기까지 내가 지금까지 가지고있는 것이있다.로직 내부에 스크립트가있는 경우

#!/usr/bin/expect -f 

set ipaddress [lindex $argv 0]; 
spawn ssh [email protected]$ipaddress 
expect "Are you sure you want to continue connecting (yes/no)?" 
send "yes\r" 
expect "[email protected]$ipaddress's password:" 
send "password\r" 
set prompt {\$ $} 
expect -re $prompt 
send "$command\r" 
expect -re $prompt 
send "quit\r" 
interact 

내가 구축해야 할 부분/다음 로직이 두 줄 경우 :

expect "Are you sure you want to continue connecting (yes/no)?" 
send "yes\r" 

논리 흐름이 될 것이다가 :

나는이 작업을 수행 할 수있는 방법
if expect "Are you sure you want to continue connecting (yes/no)?" 
then send "yes\r" 
else 
expect "[email protected]$ipaddress's password:" 
etc.. 

?

답변

1

다음 코드 수정으로이 기능을 사용할 수 있습니다.

expect { 
    "Are you sure you want to continue connecting (yes/no)?" { 
     send "yes\r" 
     exp_continue 
    } 
    "[email protected]$ipaddress's password:" { 
     send "password\r" 
    } 
    } 
+1

잘못된 장소에'exp_continue'가 있습니다 : "확실합니까?"블록에 있어야합니다. 두 경우 모두 암호를 입력해야하기 때문입니다. –

+0

귀하의 제안을 반영하여 제 대답을 업데이트했습니다. 나는 exp_continue를 옮긴 이후로 아직 하나의 실패를 겪지 않았으므로 당신이 옳았다. – user53029

관련 문제