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/

相关文章:

bash - 下载完成之前使用 SFTP 和 mget 完成的 Shell 脚本

ssh - 我是否可以使用Expect SSH进入计算机并使用单个bash行进行交互?

linux - 在 Linux 内核模块中监听新进程

linux - 一个 Linux 工具,它会在我键入时显示错误,Visual Studio 风格

linux - 尝试放置错误变量时如何修复 Tcl 'Command not found' 错误?

在expect命令中进行Bash数组变量扩展

linux - 如何在 QEMU 上模拟 Raspberry Pi 2?

c - X11 应用程序无法使用/双缓冲绘制

linux - 递归斐波那契组装

Expect 脚本不适用于多个密码请求