如何在 Rundeck 中使用单/双引号 var 重定向长字符串?

问题描述

感谢您花时间阅读这个问题。

我有一个包含多个步骤的 Rundeck 工作。基本上,第 1 步和第 2 步是获取 ' ' 下的长字符串。例子: 'This is a long string.. and is also under "double quotes" '。 -> 该变量以如下形式存储:@option.mylongstring@

我的 Rundeck 工作的第三步失败了,因为我的字符串中有单引号和多引号的问题。我想从那个长字符串中提取特定值

我的解决方案是将 @option.mylongstring@内容发送到临时文件中,然后应用 sed 将单引号转换为双引号 (sed "s/'/\"/g"),然后从中提取我需要的信息。>

无论如何,似乎 Rundeck 中没有发生重定向echo @option.mylongstring@ &> $TEMPFILE 什么都不做,生成一个文件

有人遇到过同样的问题吗?

解决方法

使用内联脚本没有问题,让我分享作业定义示例:

<joblist>
  <job>
    <defaultTab>nodes</defaultTab>
    <description></description>
    <executionEnabled>true</executionEnabled>
    <id>5e7123ce-c9b7-4bfa-a0e8-6484a9bd7c4f</id>
    <loglevel>INFO</loglevel>
    <name>LongStringExample</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <plugins />
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <fileExtension>.sh</fileExtension>
        <script><![CDATA[echo 'hello "world"' > myfile.txt]]></script>
        <scriptargs />
        <scriptinterpreter>/bin/bash</scriptinterpreter>
      </command>
    </sequence>
    <uuid>5e7123ce-c9b7-4bfa-a0e8-6484a9bd7c4f</uuid>
  </job>
</joblist>

使用选项:

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option name='opt1' />
      </options>
    </context>
    <defaultTab>nodes</defaultTab>
    <description></description>
    <executionEnabled>true</executionEnabled>
    <id>22d7286f-7be9-4aaf-92ae-8e5bf5277d67</id>
    <loglevel>INFO</loglevel>
    <name>AnotherLongStringExample</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <plugins />
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <fileExtension>.sh</fileExtension>
        <script><![CDATA[echo 'this is another "@option.opt1@"' > another_file.txt]]></script>
        <scriptargs />
        <scriptinterpreter>/bin/bash</scriptinterpreter>
      </command>
    </sequence>
    <uuid>22d7286f-7be9-4aaf-92ae-8e5bf5277d67</uuid>
  </job>
</joblist>