使用 Vagrantfile 中的 Expect 脚本进行配置 - 执行期间文件不存在的问题

使用 Vagrantfile 中的 Expect 脚本进行配置 - 执行期间文件不存在的问题

是否可以使用 Vagrantfile 中的 Expect 脚本进行配置?

看起来 installOracle.exp 脚本中的文件在适当的时候不存在(请参阅错误日志):

spawn "/var/wminst/vm_provision/oracle_installer/installOracleDatabase.sh"

文件就在那里!:)

[vagrant@wemdbc01 ~]$ ls -la /var/wminst/vm_provision/oracle_installer/installOracleDatabase.sh
-rwxrwxrwx. 1 vagrant vagrant 541 May 25 08:43 /var/wminst/vm_provision/oracle_installer/installOracleDatabase.sh

我的 Vagrantfile 的相关部分:

  [...]
  db.vm.synced_folder ".", "/vagrant", disabled: true
  db.vm.synced_folder "C:/Installers", "/var/wminst"
  db.vm.provision :shell, :inline  => "yum -y install expect"
  db.vm.provision :shell, :inline => "expect /var/wminst/vm_provision/oracle_installer/installOracle.exp" 
end

安装Oracle.exp:

#!/usr/bin/env expect

set timeout 20

spawn "/var/wminst/vm_provision/oracle_installer/installOracleDatabase.sh"

expect "replace Disk1/upgrade/gen_inst.sql?" { send "N\r" }
expect "Specify the HTTP port that will be used for Oracle Application Express" { send "\r" }
expect "Specify a port that will be used for the database listener" { send "\r" }
expect "initial configuration:" { send "root\r" }
expect "Confirm the password:" { send "root\r" }
expect "Do you want Oracle Database 11g Express Edition to be started on boot" { send "y\r" }
expect eof
expect eof
expect "Installation completed successfully." { send "\r" }
expect eof

错误:

==> wemdbc01: Running provisioner: shell...
    wemdbc01: Running: inline script
==> wemdbc01: spawn /var/wminst/vm_provision/oracle_installer/installOracleDatabase.sh
==> wemdbc01: couldn't execute "/var/wminst/vm_provision/oracle_installer/installOracleDatabase.sh": no such file or directory
==> wemdbc01:     while executing
==> wemdbc01: "spawn "/var/wminst/vm_provision/oracle_installer/installOracleDatabase.sh""
==> wemdbc01:     (file "/var/wminst/vm_provision/oracle_installer/installOracle.exp" line 5)
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

编辑1:更改:

#!/bin/bash

#!/usr/bin/env bash

现在错误日志:

==> wemdbc01: Running provisioner: shell...
    wemdbc01: Running: inline script
==> wemdbc01: spawn /var/wminst/vm_provision/oracle_installer/installOracleDatabase.sh
: No such file or directory bash
==> wemdbc01: expect: spawn id exp5 not open
==> wemdbc01:     while executing
==> wemdbc01: "expect "Specify the HTTP port that will be used for Oracle Application Express" { send "\r" }"
==> wemdbc01:     (file "/var/wminst/vm_provision/oracle_installer/installOracle.exp" line 8)
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

答案1

有问题的脚本是在 Windows 上生成的,这意味着它有 DOS 换行符。这导致脚本无法在 Unix VM 上执行。

不过,虚拟机在 Windows 上运行这一事实并不是问题。

相关内容