I have a need to update a bash/perl script to create a file with a system process (mktemp
), I need to set the filename for creation, and for this I want to use the current system date:
LOGFILE=$(/bin/mktemp /folder/program_log.$(date +'%Y%m%d'))
I have since writing this found that the Bash script doesn't create any output and no file exists on the filesystem. I have only changed this line so I believe this is the cause.
result desired:
LOGFILE = /folder/program_log.20230718
I am not very familiar with Bash. How can I achieve the intended result?
It appears that the issue was not the DATE
aspect at all, but that mktemp
requires some XXXX
randomisation in the string filename to work correctly.
Using touch
command instead resolves this issue.
LOGFILE=$(/bin/touch /folder/program_$(date +'%d-%m-%Y_%H-%M').log)