【问题标题】:Error 'unexpected end of file /vagrant/provision/prep_server.sh' by vagrant up commandvagrant up 命令错误“文件/vagrant/provision/prep_server.sh 意外结束”
【发布时间】:2016-11-28 18:00:28
【问题描述】:

我试着做vagrant up。 我在主机上的环境

  • 微软视窗 10
  • 虚拟盒子 5.1.10
  • 流浪者 1.8.6

Vagrant 得到 box bento/debian-8.6,设置端口,挂载共享文件夹,然后返回错误

==> myvag: /vagrant/provision/prep_server.sh: line 2: $'\r': command not found
==> myvag: /vagrant/provision/prep_server.sh: line 4: $'\r': command not found
==> myvag: /vagrant/provision/prep_server.sh: line 10: $'\r': command not found
==> myvag: Updating Aptitude
==> myvag: /vagrant/provision/prep_server.sh: line 14: $'\r': command not found
==> myvag: Removing exim4
==> myvag: /vagrant/provision/prep_server.sh: line 20: $'\r': command not found
==> myvag: Performing an safe-upgrade
==> myvag: Reading changelogs...
==> myvag: Done with safe-upgrade
==> myvag: /vagrant/provision/prep_server.sh: line 25: $'\r': command not found
==> myvag: Adding dotdeb dependencies to apt sources if not there.
==> myvag: /vagrant/provision/prep_server.sh: line 27: $'\r': command not found
==> myvag: /vagrant/provision/prep_server.sh: line 30: $'\r': command not found
==> myvag: Adding dotdeb GPG Key
==> myvag: /vagrant/provision/prep_server.sh: line 42: syntax error: unexpected end of file

此文件的内容在下面

#!/bin/bash

export DEBIAN_FRONTEND=noninteractive

############ Ultimately, this is a HACK: ###############
## Because of libssl and heartbleed, there are some
## debian propts that come up and destroy screw up
## Our provisioning scripts in salt and make the output
## really funny.

# Update our packages data
echo "Updating Aptitude"
sudo aptitude update > /dev/null

# exim4 is the stupid package causing the prompt to occur.
# It was just easier to remove it than automate the lib's
# Upgrade screen.
echo "Removing exim4"
sudo aptitude purge -y -q -f exim4 > /dev/null

echo "Performing an safe-upgrade"
# Do an upgrade of the existing stuff
sudo -E bash -c 'aptitude safe-upgrade -y -f > /dev/null'
echo "Done with safe-upgrade"

echo "Adding dotdeb dependencies to apt sources if not there."
grep -q -F 'packages.dotdeb.org' /etc/apt/sources.list ||
echo "deb http://packages.dotdeb.org jessie all
deb-src http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list

echo "Adding dotdeb GPG Key"
if ! apt-key list | grep -q -F  'dotdeb'; then
    wget https://www.dotdeb.org/dotdeb.gpg
    apt-key add dotdeb.gpg
    rm dotdeb.gpg
else
    echo "Dotdeb GPG Key present"
fi

echo "Updating apt-get"
apt-get update

据我了解,它可能与结尾\r\n 相关,但我该如何解决。

同时我的同事对vagrant up 没有问题,但他在主机上使用 Ubuntu。

【问题讨论】:

    标签: vagrant debian windows-10 virtual-machine virtualbox


    【解决方案1】:

    你的文件有windows编码的回车,这在linux世界是不同的。

    您的解决方案:

    1. 通过 dos2unix 脚本运行您的文件 (http://dos2unix.sourceforge.net)

    2. Windows 上最高级的编辑器(UltraEdit、Notepad++)允许您保存专门用于 linux 的文件格式(例如 UltraEdit 具有 File/convert 选项以转换为 linux)

    【讨论】:

    • 你是什么意思“擦文件”。,我运行命令 vagrant up 并且这个文件是自动创建的
    • 该文件不是由 vagrant 创建的,这是您自己的配置脚本,您需要确保它没有使用 Windows 特定的回车编码
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-04
    • 1970-01-01
    • 2023-03-17
    相关资源
    最近更新 更多