Hang on using the date command under Linux crontab

  In the test environment, a colleague developed their own set of feedback crontab does not take effect, regular tasks as follows:

*/6 * * * * date >> /usr/local/log/log_$(date +%Y%m%d%H%M).txt

  At first glance, it seems no problem.
  According to the first idea to test:

  1. execute directly on the command line, no problem

# date >> /usr/local/log/log_$(date +%Y%m%d%H%M).txt

  2. View / va / log / cron log, did not find the problem
  3. cron service is normal
  4. environment variable, date using the absolute path? Test it, into the regular tasks

 */6 * * * * date >> /home/a.txt

  Regular tasks normally performed.
  5. That is, the problem should be $ (date +% Y% m % d% H% M) in question, executing on the terminal
  

`date +"%Y%m%d_%H:%M"` 和 $(date +"%Y%m%d_%H:%M")

  In crontab under ineffective, requires the use of the following form:

`date +"\%Y\%m\%d_\%H:\%M"` 和 $(date +"\%Y\%m\%d_\%H:\%M")

Guess you like

Origin www.cnblogs.com/doctormo/p/12003771.html