2013-03-15 22 views
5

Sono script di shell, come di seguito:Come passare variabili da uno script di shell ad uno script previsto?

#!/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 

In script precedente, sto recupero gateway dalla selezione input dell'utente & cercando di passare per il mio script abc.sh che si aspettano scriptshown di seguito:

#!/usr/bin/expect 

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

Ma non sono in grado di passare la variabile gateway dallo script di shell per prevedere lo script. Qualcuno può dirmi come ottenere questo ?? Si prega di notare che ho bisogno di utilizzare script di shell solo per motivi di eredità (Non può usare TCL script o non riesco a fare tutto quanto in aspettarsi stesso script)

risposta

12

Dal vostro script di shell:

/mypath/abc $gateway 

dallo script aspetta :

#!/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 
Problemi correlati