Search code examples
bashshellrundeck

cron expression with asterisk character included


I have this code and I am trying to run on a remote node in Rundeck with input option as 0 * * * *

#!/bin/bash
cron_expression="$1"
echo "Crontab expression: $cron_expression"

When I run this via the terminal it's working fine. Also, it works well when I execute it locally on Rundeck. But when I pass the same input and execute it on remote nodes in Rundeck, it's reading '*' as a wildcard character. The script file is on Rundeck server and reading from there. Can someone suggest how to run it on Rundeck remote nodes?


Solution

  • You need to use an option in your Rundeck job to pass it to your script (use the @option.myoption@ format in inline-scripts steps or $RD_OPTION_MYOPTION format on "external scripts" steps). In that way, you can pass any value to your script. I left a job definition example tested on local and remote SSH nodes, this example uses your script as inline-script step. Take a look:

    - defaultTab: nodes
      description: ''
      executionEnabled: true
      id: 11dec4c7-4514-42e3-baef-d777ba1294de
      loglevel: INFO
      name: TestCronString
      nodeFilterEditable: false
      nodefilters:
        dispatch:
          excludePrecedence: true
          keepgoing: false
          rankOrder: ascending
          successOnEmptyNodeFilter: false
          threadcount: '1'
        filter: .*
      nodesSelectedByDefault: true
      options:
      - name: expression
        value: 0 * * * *
      plugins:
        ExecutionLifecycle: null
      scheduleEnabled: true
      sequence:
        commands:
        - fileExtension: .sh
          interpreterArgsQuoted: false
          script: |
            #!/bin/bash
            cron_expression="@option.expression@"
            echo "Crontab expression: $cron_expression"
          scriptInterpreter: /bin/bash
        keepgoing: false
        strategy: node-first
      uuid: 11dec4c7-4514-42e3-baef-d777ba1294de
    

    Check the result here.