문제

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?

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top