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 

1 Answer 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.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.