Trying to test something and not quite nailing it either way I've tried, so not sure if I'm being silly or not.
Essentially I need to parse a string to ipa-getcert's post-save argument which should include the year of the certificate renewal. This means the script will run once to request the certificate and then the current year can be used (simple). But then when ipa-getcert renews a certificate it will run a command with arguments post-save, and it's at this time that the year of the renewal must be used. The whole string to get a certificate issued including the post-save option [-C] is:
sudo ipa-getcert request -N $CERT_CN -K HTTP/$CERT_CN -k /etc/ssl/private/${CERT_CN}.key -f /etc/ssl/certs/${CERT_CN}.crt \
-D $CERT_CN -C "$INST_CERT -n ${CERT_NAME}_"'$(date +"%Y")'" $INST_OPTS $PAN_MGMT"
Attempting to test this I tried the following, but the date is never expanded. Is there a better way to test this, apart from using ipa-getcert to test?
$ txt="The year is: "
$ echo $txt$(date +"%Y")
The year is: 2023
$ echo $txt'$(date +"%Y")'
The year is: $(date +"%Y")
$ echo $(echo $txt'$(date +"%Y")')
The year is: $(date +"%Y")
But echoing the string does, so the single quotes seem to remain even when not printed on screen.
$ echo The year is: $(date +"%Y")
The year is: 2023
Undoubtedly I'm missing something trivial here.
[EDIT:] But then the following works fine, so maybe I'm just paranoid?
$ mkdir $(date +"%Y")
$ test2="ll "'$(date +"%Y")'
$ echo $test2
ll $(date +"%Y")
$ eval $test2
total 8
drwxrwxr-x 2 user group 4096 Apr 24 20:01 ./
drwxr-xr-x 13 user group 4096 Apr 24 20:01 ../
systemctl restart xyz.service
is enough.Hence I want to be able to parse a string like:
– dmgeurts Apr 24 '23 at 21:44-C "pan_instcert -n fw.local.local_$(date +"%Y") fw.local.local
without the date being interpreted when the command is executed that takes this string.