-1
我有一个.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)
expect是Tcl的扩展,而Tcl不使用'variable = value'语法。对于这两种语言(shell和expect),您都不能使用相同的配置文件,而无需使用更多的解析代码将shell语法转换为Tcl。 –