我有一个bash资源,在尝试循环执行某些ddl脚本时失败。没有for循环(和文字脚本名称)的相同语法在Chef中运行良好,并且它都可以在终端中使用for循环:
bash "run_ddl_create_tenants" do
user "#{ENV['CHEFUSER']}"
environment "PATH" => "/usr/lib/oracle/12.1/client64/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin:/opt/aws/bin:/home/#{ENV['CHEFUSER']}/bin"
code <<-EOH
for f in $(grep '>' /tmp/diffs/tnntdiff | cut -c 3-); do
sqlplus "admin/password@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$(aws rds describe-db-instances --db-instance-identifier #{ENV['CLIENTID']}-#{ENV['CTCENV']} | grep 'Address' | cut -d\\\" -f4))(PORT=#{ENV['DBPORT']}))(CONNECT_DATA=(SID=#{ENV['CLIENTID']}#{ENV['CTCENV']})))" <<-SQLEOH
@#{ENV['CTC_CONFIGURATION']}/ddl/ddl_create_tenant_$f.sql
#{ENV['DBPASSWD']}
exit;
SQLEOH
done
EOH
end
我收到的错误表明SQLEOH分隔符和意外的文件结尾存在问题。
STDERR: /tmp/chef-script20151012-25490-16o11q7: line 7: warning: here-document at line 2 delimited by end-of-file (wanted `SQLEOH')
/tmp/chef-script20151012-25490-16o11q7: line 8: syntax error: unexpected end of file
终端命令与Chef解释此资源的方式之间的断开是什么?
答案 0 :(得分:0)
知道了,在分隔符之前发出了空格。删除了SQLEOH上的缩进并成功连接