-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。 –