AWS EC2 用户数据未正确解码

AWS EC2 User Data Not Decoding Correctly

我正在尝试创建一个 EC2 实例来托管 Perforce 服务器。我的实例配置了以下用户数据:

#!/bin/bash

# Add a newline to the ec2-user prompt string
echo PS1=\"\n$PS1\" >> /home/ec2-user/.bashrc

# Update all packages
yum update –y

# Install Perforce packages
# The RHEL/7 part of the baseurl should be replaced with
# the latest RHEL version that both Amazon and Perforce support
rpm –import https://package.perforce.com/perforce.pubkey
cd /etc/yum.repos.d/
echo [perforce] > perforce.repo
echo name=Perforce >> perforce.repo
echo baseurl=http://package.perforce.com/yum/rhel/7/x86_64 >> perforce.repo
echo enabled=1 >> perforce.repo
echo gpgcheck=1 >> perforce.repo
yum install –y helix-p4d

# Make directories for the server, owned by new “perforce” user
cd /opt/perforce/servers/
mkdir danware
cd danware
mkdir danware-db danware-chkpts journal
chown –R perforce:perforce danware

我已经测试了上面的每一个命令,并且知道按照这个顺序手动执行它们是有效的。然而,Amazon 的 base64 encode/decode 系统的某些方面似乎受到了阻碍。当我在启动(并通过所有系统检查)后从 EC2 控制台转到 "Actions > Instance Settings > View/Change User Data" 时,我看到以下用户数据。请注意,几乎每个连字符“-”都已被一些奇怪的 "a" 字符替换。

但是,我不确定这是不是问题所在,因为 /var/log/cloud-init-output.log 的日志文件给了我以下输出(我用 [...] 替换了一些重复的文本以保存 space).请注意显示 Failed running /var/lib/cloud/instance/scripts/part-001 的行我已验证此 part-001 文件实际上 确实 具有正确显示的连字符。

[...]
Cloud-init v. 0.7.6 running 'modules:final' at Fri, 09 Sep 2016 06:23:39 +0000. Up 86.66 seconds.
Loaded plugins: priorities, update-motd, upgrade-helper
No Match for argument: –y
No packages marked for update
RPM version 4.11.2
Copyright (C) 1998-2002 - Red Hat, Inc.
This program may be freely redistributed under the terms of the GNU GPL

Usage: rpm [-aKfgpqVcdLilsiv?] [-a|--all] [-f|--file] [-g|--group] [...]
Loaded plugins: priorities, update-motd, upgrade-helper
Resolving Dependencies
--> Running transaction check
---> [...]

Dependencies Resolved

================================================================================
 Package                  Arch        Version               Repository     Size
================================================================================
Installing:
 helix-p4d                x86_64      2016.1-1429894        perforce       24 k
Installing for dependencies:
 helix-cli                x86_64      2016.1-1429894        perforce      8.8 k
 helix-cli-base           x86_64      2016.1-1429894        perforce      1.4 M
 helix-p4d-base           x86_64      2016.1-1429894        perforce      3.1 k
 helix-p4d-base-16.1      x86_64      2016.1-1429894        perforce      2.4 M
 helix-p4dctl             x86_64      2016.1-1429894        perforce      1.2 M

Transaction Summary
================================================================================
Install  1 Package (+5 Dependent packages)

Total download size: 5.0 M
Installed size: 13 M
Is this ok [y/d/N]: Exiting on user command
Your transaction was saved, rerun it with:
 yum load-transaction /tmp/yum_save_tx.2016-09-09.06-23.dRP_r2.yumtx
/var/lib/cloud/instance/scripts/part-001: line 22: cd: /opt/perforce/servers/: No such file or directory
chown: invalid user: ‘–R’
Sep 09 06:23:41 cloud-init[2517]: util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/part-001 [1]
Sep 09 06:23:41 cloud-init[2517]: cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
Sep 09 06:23:41 cloud-init[2517]: util.py[WARNING]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python2.7/dist-packages/cloudinit/config/cc_scripts_user.pyc'>) failed
Cloud-init v. 0.7.6 finished at Fri, 09 Sep 2016 06:23:41 +0000. Datasource DataSourceEc2.  Up 88.53 seconds

更烦人的是,我假设日志文件中早期的 No Match for argument: –y 行是指我的用户数据中的 yum update -y 行。果然,只是 运行 来自 EC2 documentation 页面的示例用户数据脚本,它也使用了 yum update -y,给了我同样的 error/warning!亚马逊自己的示例脚本不起作用!?那么谁能回答为什么 A) AWS 没有正确显示用户数据代码,以及 B) 为什么我的用户数据会产生上面显示的错误?非常感谢您的帮助!

对于诸如

这样的行
yum update –y

您使用的角色是"EN DASH U+2013"

连字符的常用字符是 "HYPHEN-MINUS U+002D"

修复您的用户数据源以使用 "hyphen minus" 再试一次

我通过剪切 n 粘贴到这个在线站点来检查字符代码 http://www.fileformat.info/info/unicode/char/search.htm?q=-&preview=entity

不知道你是否能看出区别,但这是你的连字符

yum update –y

这是一个 "hyphen minus"

yum update -y