1

If I put the following in crontab -e:

* * * * * date +"%Y-%m-%d" > /home/apps/temp/env.txt

there is no env.txt created.

If I change the above line to:

* * * * * date > /home/apps/temp/env.txt

env.txt is created properly.

How can I format date in cron?

fedorqui
  • 275,237
  • 103
  • 548
  • 598
ohho
  • 50,879
  • 75
  • 256
  • 383
  • Possible duplicate of [Why percent signs (%) do not work in crontab?](http://stackoverflow.com/questions/16238460/why-percent-signs-do-not-work-in-crontab) – fedorqui Apr 25 '16 at 11:37

1 Answers1

1

You need to escape each one of the %:

* * * * * date +"\%Y-\%m-\%d" > /home/apps/temp/env.txt

Or even better, remove the quotes and leave like this:

* * * * * date +\%Y-\%m-\%d > /home/apps/temp/env.txt
fedorqui
  • 275,237
  • 103
  • 548
  • 598