I have a cron job that copies its log file daily to my home folder.
Everyday it overrides the existing file in the destination folder, which is expected. I want to preserve the log from previous dates so that next time it copies the file to destination folder, it preserves the files from previous dates.
How do I do that?
The best way to manage cron logs is to have a wrapper around each job. The wrapper could do these things, at the minimum:
Here is a bare bones version of a cron wrapper:
Your cron command line would look like:
Once this is in place, we can have another job called
cron_log_cleaner
which can remove older logs. It's not a bad idea to call the log cleaner from the cron wrapper itself, at the end.An example:
The log would contain this after running the wrapped cron job:
Insert
to your
cp
command, like this:so it will copy
src_file
todst_file_2017-01-20
upd:
As @tripleee noticed,
%
character should be escaped incron
, so your cron job will look like this: