用于创建 yum 存储库定义文件的 bash 脚本

用于创建 yum 存储库定义文件的 bash 脚本

如何获取下面的 bash 脚本来创建yum可以成功促进安装的存储库定义文件mongodb

正如您所看到的,当前版本的脚本导致了失败,您可以在下面阅读。

当前 bash 脚本的相关部分是:

echo "[STARTING TASK 4: Install MongoDB]"
echo "... About to create the repo file with a cat command ..."
cat >/etc/yum.repos.d/mongodb-org.repo <<EOL
line 1, [mongodb-org-3.4]
line 2, name=MongoDB Repository
line 3, baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
line 4, gpgcheck=1
line 5, enabled=1
line 6, gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
line 7 line
... 
EOL

echo "... About to confirm with yum repolist"
yum repolist
echo "... About to yum -y install mongodb-org"
yum -y install mongodb-org
echo "... About to systemctl start mongod"
systemctl start mongod

脚本运行时控制台输出为:

build   18-Dec-2017 17:09:07    [STARTING TASK 4: Install MongoDB]
build   18-Dec-2017 17:09:07    ... About to create the repo file with a cat command ...
build   18-Dec-2017 17:09:07    ... About to confirm with yum repolist
build   18-Dec-2017 17:09:07    Loaded plugins: fastestmirror, langpacks
error   18-Dec-2017 17:09:07    
error   18-Dec-2017 17:09:07    
error   18-Dec-2017 17:09:07    File contains no section headers.
error   18-Dec-2017 17:09:07    file: file:///etc/yum.repos.d/mongodb-org.repo, line: 1
error   18-Dec-2017 17:09:07    'line 1, [mongodb-org-3.4]\n'
build   18-Dec-2017 17:09:07    ... About to yum -y install mongodb-org
build   18-Dec-2017 17:09:07    Loaded plugins: fastestmirror, langpacks
error   18-Dec-2017 17:09:07    
error   18-Dec-2017 17:09:07    
error   18-Dec-2017 17:09:07    File contains no section headers.
error   18-Dec-2017 17:09:07    file: file:///etc/yum.repos.d/mongodb-org.repo, line: 1
error   18-Dec-2017 17:09:07    'line 1, [mongodb-org-3.4]\n'
build   18-Dec-2017 17:09:07    ... About to systemctl start mongod
error   18-Dec-2017 17:09:07    Failed to start mongod.service: Unit not found.

正如您所看到的,该错误似乎是由于脚本无法创建/etc/yum.repos.d/mongodb-org.repo.相比之下,我能够使用手动命令来创建该文件的工作版本。

答案1

我相信解决您的问题的最短方法是重新生成代码;将其更改为:

cat >/etc/yum.repos.d/mongodb-org.repo <<EOL
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/6Server/mongodb-‌​org/3.6/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
EOL

这样就不会打印无关的文本。我不知道第 7 行或之后的内容,但继续删除前导“line ...”文本的想法。

相关内容