代码之家  ›  专栏  ›  技术社区  ›  aphexlog

厨师食谱-用sed命令替换Linux文件中的文本(接收错误)

  •  0
  • aphexlog  · 技术社区  · 7 年前

    我在厨师食谱中使用以下代码:

    bash 'replace_text' do
        cwd ::File.dirname('/data01/nodemanager/bin')
        code <<-EOH
          sed 's/NODEMGR_HOME=.*/NODEMGR_HOME="\/data01\/nodemanager"/g' startNodeManager.sh
          EOH
      end
    

    我试图替换的文本是行中包含的所有内容 NODEMGR_HOME= startNodeManager.sh 位于 /data01/nodemanager/bin

    运行配方时,我收到以下输出:

           Running handlers:
           [2017-11-21T23:58:22+00:00] ERROR: Running exception handlers
           [2017-11-21T23:58:22+00:00] ERROR: Running exception handlers
           Running handlers complete
           [2017-11-21T23:58:22+00:00] ERROR: Exception handlers complete
           [2017-11-21T23:58:22+00:00] ERROR: Exception handlers complete
           Chef Client failed. 0 resources updated in 01 seconds
           [2017-11-21T23:58:22+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
           [2017-11-21T23:58:22+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
           [2017-11-21T23:58:22+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
           [2017-11-21T23:58:22+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
           [2017-11-21T23:58:22+00:00] ERROR: bash[replace_text] (domain-test::sed2 line 1) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
           ---- Begin output of "bash"  "/tmp/chef-script20171121-11258-vwwwm6" ----
           STDOUT:
           STDERR: sed: -e expression #1, char 34: unknown option to `s'
           ---- End output of "bash"  "/tmp/chef-script20171121-11258-vwwwm6" ----
           Ran "bash"  "/tmp/chef-script20171121-11258-vwwwm6" returned 1
           [2017-11-21T23:58:22+00:00] ERROR: bash[replace_text] (domain-test::sed2 line 1) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
           ---- Begin output of "bash"  "/tmp/chef-script20171121-11258-vwwwm6" ----
           STDOUT:
           STDERR: sed: -e expression #1, char 34: unknown option to `s'
           ---- End output of "bash"  "/tmp/chef-script20171121-11258-vwwwm6" ----
           Ran "bash"  "/tmp/chef-script20171121-11258-vwwwm6" returned 1
           [2017-11-21T23:58:22+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
           [2017-11-21T23:58:22+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
    >>>>>> ------Exception-------
    >>>>>> Class: Kitchen::ActionFailed
    >>>>>> Message: 1 actions failed.
    >>>>>>     Converge failed on instance <default-ubuntu-1404>.  Please see .kitchen/logs/default-ubuntu-1404.log for more details
    >>>>>> ----------------------
    >>>>>> Please see .kitchen/logs/kitchen.log for more details
    >>>>>> Also try running `kitchen diagnose --all` for configuration
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   coderanger    7 年前

    你的反斜杠上没有足够的逃脱能力。请记住,首先是Ruby字符串,然后是bash字符串,然后是sed参数。您还可以通过使用 line poise-file 而不是烹饪书。