我想从bash变量创建host_install.py。 所以我试过以下:
#!/bin/bash
CM_HOST="10.0.5.99"
CM_USER="admin"
CM_PASSWORD="admin"
CM_CLUSTER_NAME="cluster"
INSTANCE_TYPE=`wget -q -O- http://169.254.169.254/latest/meta-data/instance-type`
cat > /tmp/host_install.py <<EOF
import socket
import commands
from time import sleep
cluster_name = "$CM_CLUSTER_NAME"
role_template = "$INSTANCE_TYPE"
print cluster_name
print role_template
EOF
chmod a+x /tmp/host_install.py
/tmp/host_install.py
这是打印
$CM_CLUSTER_NAME
$INSTANCE_TYPE
而不是
cluster
c3.2xlarge
我在这里做错了什么?
答案 0 :(得分:1)
import os
cluster_name = os.environ['CM_CLUSTER_NAME']
role_template = os.environ['INSTANCE_TYPE']
Windows上的 Python default installation为C:\Python
。如果你想在运行python时找到答案,你可以这样做:
import sys
print sys.prefix