Redhat – Rysnc Dynamic Log File Name

cronredhatrsync

I am setting up rsync cron to run every hour to sync up 2 servers. My question is how do I make the log file name that it is saving to in the format log_file-{Year}-{Month}-{Date}.log with the year, month, and date changing accordingly?

Thanks in advance.

Best Answer

I assume you're using --log-file? Then you can do something like this:

date=`date +%Y-%m-%d`
rsync --log-file=log_file-$date (...)

Or, in a single line if you're putting this directly in your crontab:

rsync --log-file=log_file-`date +%Y-%m-%d` (...)