gpt4 book ai didi

xml - 使用 chef 的 sed 命令

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:37:31 25 4
gpt4 key购买 nike

您好,我在 Chef Recipe 中使用 sed 命令,但出现抛出错误。但是如果我只在 CLI 上运行 sed 命令,它就可以工作。任何帮助表示赞赏。

我的 sed 命令是 -

sed -i -e "/<BigSQL>/,/<\/BigSQL>/ s|<username>[0-9a-z.]\{1,\}</username>|<username>bigsql</username>|" /home/biadmin/install.xml

我的 Chef Recipe 是 -

bash "change_bigsqluser" do
user "root"
code <<-EOH
sed -i -e "/<BigSQL>/,/<\/BigSQL>/ s|<username>[0-9a-z.]\{1,\}</username>|<username>bigsql</username>|" /home/biadmin/install.xml
EOH
end

这里是错误

Error executing action `run` on resource 'bash[change_bigsqluser]'
================================================================================


Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of "bash" "/tmp/chef-script20140807-4025602-160wvt2" ----
STDOUT:
STDERR: sed: -e expression #1, char 15: unknown command: `B'
---- End output of "bash" "/tmp/chef-script20140807-4025602-160wvt2" ----
Ran "bash" "/tmp/chef-script20140807-4025602-160wvt2" returned 1


Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/biginsights/recipes/temp.rb

22: bash "change_bigsqluser" do
23: user "root"
24: code <<-EOH
25: sed -i -e "/<BigSQL>/,/<\/BigSQL>/ s|<username>[0-9a-z.]\{1,\}</username>|<username>bigsql</username>|" /home/biadmin/install.xml
26: EOH
27: end



Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/biginsights/recipes/temp.rb:22:in `from_file'

bash("change_bigsqluser") do
action "run"
retries 0
retry_delay 2
guard_interpreter :default
command "\"bash\" \"/tmp/chef-script20140807-4025602-160wvt2\""
backup 5
returns 0
user "root"
code "sed -i -e \"/<BigSQL>/,/</BigSQL>/ s|<username>[0-9a-z.]{1,}</username>|<username>bigsql</username>|\" /home/biadmin/install.xml\n"
interpreter "bash"
cookbook_name "biginsights"
recipe_name "temp"
end



[2014-08-07T04:25:49-07:00] INFO: Running queued delayed notifications before re-raising exception

Running handlers:
[2014-08-07T04:25:49-07:00] ERROR: Running exception handlers
Running handlers complete

[2014-08-07T04:25:49-07:00] ERROR: Exception handlers complete
[2014-08-07T04:25:49-07:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated in 7.374318882 seconds
[2014-08-07T04:25:49-07:00] ERROR: bash[change_bigsqluser] (biginsights::temp line 22) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of "bash" "/tmp/chef-script20140807-4025602-160wvt2" ----
STDOUT:
STDERR: sed: -e expression #1, char 15: unknown command: `B'
---- End output of "bash" "/tmp/chef-script20140807-4025602-160wvt2" ----
Ran "bash" "/tmp/chef-script20140807-4025602-160wvt2" returned 1
[2014-08-07T04:25:49-07:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

最佳答案

由于您只执行一个命令并且没有使用任何 bash 功能,所以我会使用 execute资源:

execute "Do some sed" do
command "sed -i '/<BigSQL>/,/</BigSQL>/ s|<username>[0-9a-z.]{1,}</username>|<username>bigsql</username>|' /home/biadmin/install.xml"
action :run
end

关于xml - 使用 chef 的 sed 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25155907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com