来自expect文件中的文本文件的源不起作用

时间:2017-02-17 16:10:59

标签: linux expect

我有一个.sh文件和一个.exp文件,它们都有来自其他文本文件的源文件,其中包含变量值。当我运行.sh文件时,它将执行.exp文件,但似乎当它到达该行时,它无法正确读取源文件中的值。我想知道我是否做得对。

.sh文件

#!/bin/bash
source ../common/labinfo/qcow_var.txt

cd $WORKSPACE/qcow_vnf

echo -e "** Starting qcow_vnf Installation **\n** Checking the connectivity     to Host-1...**\n"
../common/isup_addr.sh "$HOSTIP_1" 1
if [ $? -ne 0 ]
then
exit 1
fi

echo -e "** Checking the connectivity to Host-2...**\n"
../common/isup_addr.sh "$HOSTIP_2" 1
if [ $? -ne 0 ]
then
exit 1
fi 

create_vm.exp "$HOSTIP_1" "$HOSTUSER" "$HOSTPASS" "$VMNAME_1"

.exp文件

#!/opt/tools/unsupported/expect-5.39/bin/expect
source ../common/labinfo/qcow_var.txt

set HOST [ lindex $argv 0 ]
set USER [ lindex $argv 1 ]
set PASSWORD [ lindex $argv 2 ]
set VMNAME [ lindex $argv 3 ]

echo -e "** Creation of $VMNAME on $HOST begins... **\n"
spawn ssh -l $USER $HOST
expect_after eof {exit 0}
set timeout 10

expect "(yes/no)?" { send "yes\r" }
expect "password:" { send "$PASSWORD\r" }

expect "~]#" { send "date\r" }
set timeout 1200
......(etc)

和.txt文件

HOSTIP_1=172.28.152.240
HOSTIP_2=172.28.152.241
HOSTUSER="root"
....(and the rest of the variables)

1 个答案:

答案 0 :(得分:0)

我在发布问题后发现了。我对此很陌生。问题是源不能像预期的那样工作,我也使用echo预期也是错误的。我解决了我的问题,现在工作正常。