linux - 来自期望文件中的文本文件的源不起作用

标签 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)

最佳答案

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

关于linux - 来自期望文件中的文本文件的源不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42302458/

相关文章:

c# - 远程调试 .NET Core Linux Docker 容器 - "the current source is different from the version built into .dll"

python - python2.4中加载库(lib*.so)文件

linux - 未找到 mingw32[64] 安装

c - linux上进程的开始时间

expect - 可以期望在没有显式设置一个巨大的常量值的情况下被告知不要超时吗?

java - 强制 read() 方法读取最少字符数

linux - 如何使用expect替换远程主机上的IP地址

regex - 将文本从一行复制到另一行

Linux shell : my `expect` script doesn't work as expected

bash - 在 Bash 中模拟 Gromacs 中的用户交互