I'm trying to use the following to tar any file that has a date appended to it:
#!/bin/bash
createDate=[0-9]{4}-[0-9]{2}-[0-9]{2}
for file in $HOME/test/*.log.$createDate ; do
log=$(basename $file)
find . -type f | tar -zcvf $log.tar $log
done
This should tar any file with a date appended after the log extension, like test.log.2020-01-01. However, I get an error:
tar: *.log.[0-9]{4}-[0-9]{2}-[0-9]{2}: Cannot stat: No such file or directory
So, its reading this pattern literally, as a string. What I need is for it to use the pattern to match any file with that date format, after the log extension. This will eventually into the postrotate section for a logrotate configuration file, but I need to be sure it works first.