SUMMARY: Command doesn't work in cron but works in shell

From: Aleksandr Nepomnyashchiy <>
Date: Fri Aug 29 2008 - 18:53:50 EDT
Many thanks to everyone who replied and especially to Ric Anderson,
Bill R. Williams , Francisco Roque and Michael Maciolek who pointed me
to the following fragment of the man page:
 "The sixth field of a line in a crontab file is a string that
 is executed by the shell at the specified times. A percent
 character in this field (unless escaped by \ ) is translated
 to a NEWLINE character"

The following cron line has been successfully tested:
10 23 * * * mv /path/to/my/file.txt  /path/to/my/file.txt`date +\%Y\%m\%e`

=========== Original question ==============

The following command works in shell :
root@host ~ # mv /path/to/my/file.txt  /path/to/my/file.txt`date +%Y%m%e`

But doesn't work in cron :
# rotate my log
10 23 * * * mv /path/to/my/file.txt  /path/to/my/file.txt`date +%Y%m%e`

Root is getting an email :
>From root Wed Aug 27 23:10:01 2008
Return-Path: <root>
Received: (from root@localhost)
To: root
Subject: Output from "cron" command

Your "cron" job on host
mv /path/to/my/file.txt  /path/to/my/file.txt`date +

produced the following output:

mv: /path/to/my/file.txt and /path/to/my/file.txt are identical

Looks like  `date +%Y%m%e`  doesn't get interpreted the way I expect
when running from cron.

Thank you,
sunmanagers mailing list
Received on Fri Aug 29 18:56:17 2008

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:44:11 EST