I have this Shell script here:
###
# Create a folder dynamically
mkdir archived_PA_"$(date -d "6 months ago - 1 day" +%Y-%m-%d)"_"$(date -d "1 day ago" +%Y-%m-%d)"
# Move files to new folder dynamically
find ./VA -newermt $(date +%Y%m%d -d '6 months ago') ! -newermt $(date +%Y%m%d -d 'today') -exec mv -t /var/log/pentaho/archived_PA_"$(date -d "6 months ago - 1 day" +%Y-%m-%d)"_"$(date -d "1 day ago" +%Y-%m-%d)" {} +
# Archive dynamic folder
zip -r archived_PA_"$(date -d "6 months ago - 1 day" +%Y-%m-%d)"_"$(date -d "1 day ago" +%Y-%m-%d)".zip /var/log/pentaho/archived_PA_"$(date -d "6 months ago - 1 day" +%Y-%m-%d)"_"$(date -d "1 day ago" +%Y-%m-%d)"
At first, every line runs fine on command lines but when I run this Shell script with this command ./script_name.sh
then I would get the following error:
./HIX-170061.sh: line 4: $'r': command not found
find: missing argument to `-exec'
./HIX-170061.sh: line 7: $'r': command not found
adding: var/log/pentaho/archived_PA_2023-01-09_2023-07-09^M/ (stored 0%)
In short, I am able to execute other lines (except for line 4 and 7 but it’s empty line so I assume it doesn’t matter) but line 6 is where I get the error, which is find: missing argument to `-exec'
error.