Centos

用於創建 yum 儲存庫定義文件的 bash 腳本

  • December 19, 2017

如何獲取下面的 bash 腳本來創建yum可以成功安裝的 repo 定義文件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. 相比之下,我能夠使用手動命令來創建文件的工作版本。

我相信對您的問題的最短解決方案是回購生成程式碼;將其更改為:

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 …”文本的想法。

引用自:https://unix.stackexchange.com/questions/411708