如何从 Rundeck 作业中检索日期

How to retrieve date from a Rundeck job

我正在尝试在 rundeck 2.6 作业中实现这样的目标:

touch /foo/bar/${DATE:MM/dd/yyyy}-baz

但它无法正常工作,并且根本无法解释日期。有没有正确的方法来做到这一点?

您可以使用这个 bash 脚本:

#!/bin/bash
touch /foo/bar/`date "+%m/%d/%Y"`-baz

反引号充当 command substitution and replace the output of the date command in the touch 命令。

根据 date man page :

An operand with a leading plus (`+') sign signals a user-defined format string which specifies the format in which to display the date and time. The format string may contain any of the conversion specifications described in the strftime(3) manual page, as well as any arbitrary text.

日期格式字符串使用如下conversion specifier character :

  • %m The month as a decimal number (range 01 to 12). (Calculated from tm_mon.)
  • %d The day of the month as a decimal number (range 01 to 31). (Calculated from tm_mday.)
  • %Y The year as a decimal number including the century. (Calculated from tm_year)

您还可以定义一个使用该日期格式说明符的选项。 设置选项的默认值以使用说明符。例如:

<option name="date" value="${DATE:MM/dd/yyyy}-baz" />

在您的步骤中引用 ${option.date}。