2013-03-15 4 views
5

I했습니다 쉘 스크립트 :쉘 스크립트에서 expect 스크립트로 변수를 전달하는 방법은 무엇입니까? 아래

#!/usr/bin/expect 

set timeout 3 
spawn ssh "[email protected]$gateway" 
expect "password:" 
send "TSfdsHhtfs\r"; 
interact 
: 위의 스크립트에서

#!/bin/bash 

echo "Select the Gateway Server:" 
echo " 1. Gateway 1" 
echo " 2. Gateway 2" 
echo " 3. Gateway 3" 

read gatewayHost 

case $gatewayHost in 
    1) gateway="abc.com" ;; 
    2) gateway="pqr.com" ;; 
    3) gateway="xyz.com" ;; 
    *) echo "Invalid choice" ;; 
esac 

/mypath/abc 

, 나는 아래 scriptshown 기대하는 내 abc.sh 스크립트에 전달하려고 사용자 입력 선택 &에서 게이트웨이를 가져 오는거야

그러나 쉘 스크립트에서 게이트웨이 변수를 전달하여 스크립트를 기대할 수 없습니다. 아무도 이것을 달성하는 방법을 말해 줄 수 있습니까 ?? 당신의 기대 스크립트에서

/mypath/abc $gateway 

: 만 인해 기존의 이유로 쉘 스크립트를 사용해야합니다 (TCL 스크립트를 사용할 수 없습니다 또는 스크립트 자체가 기대에 모든 것을 할 수 있습니다) 쉘 스크립트에서

답변

12

을 참고하시기 바랍니다 :

#!/usr/bin/expect 

set gateway [lindex $argv 0]; # Grab the first command line parameter 

set timeout 3 
spawn ssh "[email protected]$gateway" 
expect "password:" 
send "TSfdsHhtfs\r"; 
interact 
관련 문제