I have the following user crontab entry on a RHEL 6 machine (sensitive values have been replaced):
[email protected]
0 5 * * * ~/bin/app_state.sh host-arg 9200 > ~/state/app-state-$(hostname)-$(date +%F).json
Which produces this entry in /var/log/cron
:
Apr 23 05:00:08 host CROND[13901]: (dbjobs) CMD (~/bin/app_state.sh host-arg 9200 > ~/state/app-state-$(hostname)-$(date +)
But no file.
After changing the statement to:
43 5 * * * ~/bin/app_state.sh host-arg 9200 > ~/state/app-state-static.json
I get a better log entry and the file is created at ~/state/app-state-static.json
I'm sure there's some issue with not escaping the +%F
but can't for the life of me find details of how I should be escaping it. I could wrap the filename generation inside another shell script but this is more easy to read for people coming looking for the file.
date +\%F
– Flickertail+\%F
did the trick. I'll re ask on unix stack exchange so the answer can go on record but is there a clean way to close it out here? – Kamal