2013-03-15 4 views
5

J'ai script shell comme ci-dessous:Comment passer des variables d'un script shell à un script expect?

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

dans le script ci-dessus, je suis passerelle aller chercher de la sélection d'entrée utilisateur & essayant de passer à mon script abc.sh qui est attendre en scriptshown ci-dessous:

#!/usr/bin/expect 

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

Mais je ne suis pas en mesure de passer la variable de passerelle du script shell pour attendre le script. Quelqu'un peut-il me dire comment y parvenir? S'il vous plaît noter que je dois utiliser script shell uniquement pour des raisons héritées (ne peut pas utiliser tcl script ou ne peux pas faire tout en s'attendre script)

Répondre

12

À partir de votre script shell:

/mypath/abc $gateway 

À partir de votre script expect :

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