0

in my crontab i have this

* * * * * /users/abcd/runme.sh >> /mnt/ansible/logs/runme.log

is it possible to append the date to the file with something like this? I've tried several different variations with no luck.

* * * * * /users/abcd/runme.sh >> /mnt/ansible/logs/runme_`date +%F`.log
dprivateb
  • 21
  • 1
  • 5
  • `echo "hello" > runme_$(date +%F).log` Works for me on the command line, but perhaps because this is coming through cron, you may need to specify the full path to `date` like: `echo "hello" > runme_$(/bin/date +%F).log` – JNevill Oct 30 '19 at 19:52
  • @JNevill for now my issue seems to be formatting. im getting messages from cron like this "unexpected EOF while looking for matching `)'" – dprivateb Oct 30 '19 at 20:02
  • Possible duplicate of [Append current date to the filename via Cron?](https://stackoverflow.com/q/9110663/608639), [Sending cron output to a file with a timestamp in its name](https://serverfault.com/q/117360), [How to add the logs to a crontab with time stamp](https://askubuntu.com/q/391542), [How can cron output to a new log file based on date?](https://stackoverflow.com/q/27539083/608639), [How to log cron jobs?](https://stackoverflow.com/q/4811738/608639), etc. – jww Oct 30 '19 at 21:51

1 Answers1

1

Try this.

Always works. * * * * * /users/abcd/runme.sh >> /mnt/ansible/logs/runme_$(date +%Y%m%d%H%M).log

That will work.

Patrick Mutwiri
  • 1,301
  • 1
  • 12
  • 23