0

I want to set my log file name into crontab with date - day, not current_date.

I've already success for current date like this:

00 02 * * * bash run_myscript.sh > /logs_myscript_`date "+\%Y\%m\%d"`.log 2>&1

If current date is Feb 19, my log will be logs_myscript_20190219.log but cannot work if I set - 3 day on the crontab:

Actually, I want my log file like this: logs_myscript_20190216.log

00 02 * * * bash run_myscript.sh > /logs_myscript_`date - 3 day "+\%Y\%m\%d"`.log 2>&1
2

You need to specify the date with -d:

date  -d "- 3 day"  "format"
You don't need the spaces; you can say date -d"-3day" ….

The fact that it's in a crontab command shouldn't make any difference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.