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?
1 Answers
Answers 1
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 con- tain 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 comments:
Post a Comment