我已经编写了一个/etc/rc.local脚本,它执行一个jar文件,并在完成后自动关闭系统。该脚本似乎成功启动,但最终在完成之前关闭。
#!/bin/sh
#
mv --backup=t /tmp/rc.local.log /home/hadoop/logs
exec 2> /tmp/rc.local.log # send stderr from rc.local to a log file
exec 1>&2 # send stdout to the same log file
set -x # tell sh to display commands before execution
touch /var/lock/subsys/local
EC2_INSTANCE_ID="`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id || die \"wget instance-id has failed: $?\"`"
test -n "$EC2_INSTANCE_ID" || die 'cannot obtain instance-id'
EC2_AVAIL_ZONE="`wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone || die \"wget availability-zone has failed: $?\"`"
test -n "$EC2_AVAIL_ZONE" || die 'cannot obtain availability-zone'
EC2_REGION="`echo \"$EC2_AVAIL_ZONE\" | sed -e 's:\([0-9][0-9]*\)[a-z]*\$:\\1:'`"
##########
#run hadoop job
#############
su - hadoop -c 'java -jar /home/hadoop/my.jar'
##stop instance
/opt/aws/bin/ec2-stop-instances $EC2_INSTANCE_ID --region $EC2_REGION你知道我做错了什么吗?谢谢!
发布于 2014-06-26 07:52:24
set -x如果出现exit 1或更高级别的错误,则会自动关闭脚本。
如果我是正确的,您的变量,如EC2_INSTANCE_ID,需要去掉双引号。这是因为除了$之外,双引号内的所有字符都采用字面值
试一试
EC2_INSTANCE_ID= `wget -q -O - http://169.254.169.254/latest/meta-data/instance-id || die wget instance-id has failed: "$?"`我还注意到你有相当不错的错误捕获命令,所以去掉set -x是可以的,这样你就可以在脚本退出之前看到你得到了什么错误。
我以前也从来没有见过die命令。
https://stackoverflow.com/questions/24414277
复制相似问题