title: Special escaping for crontab
body: <p>I have the following user crontab entry on a RHEL 6 machine (sensitive values have been replaced):</p>
  
  <pre><code>MAILTO=cron-errors@organisation.com
  0 5 * * * ~/bin/app_state.sh host-arg 9200 &gt; ~/state/app-state-$(hostname)-$(date +%F).json
  </code></pre>
  
  <p>Which produces this entry in <code>/var/log/cron</code>:</p>
  
  <pre><code>Apr 23 05:00:08 host CROND[13901]: (dbjobs) CMD (~/bin/app_state.sh host-arg 9200 &gt; ~/state/app-state-$(hostname)-$(date +)
  </code></pre>
  
  <p>But no file.</p>
  
  <p>After changing the statement to:</p>
  
  <pre><code>43 5 * * * ~/bin/app_state.sh host-arg 9200 &gt; ~/state/app-state-static.json
  </code></pre>
  
  <p>I get a better log entry and the file is created at <code>~/state/app-state-static.json</code></p>
  
  <p>I'm sure there's some issue with not escaping the <code>+%F</code> 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.</p>