How to retrieve date from a Rundeck job

1.2k views Asked by At

I'm trying to achieve something like this in a rundeck 2.6 job:

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

but it doesn't work properly and the date is not interpreted at all. Is there a proper way to do this?

2

There are 2 answers

0
Ortomala Lokni On BEST ANSWER

You can use this bash script :

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

The backquotes act as command substitution and replace the output of the date command in the touch command.

According to the 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.

The date format string use the following 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)
0
Alex-SF On

You can also define an option that uses that date format specifier. Set the default value of the option to use the specifier. Eg:

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

Inside your step reference the ${option.date}.