Problem
I am getting some unusual results from cron(C), when my
crontab(C) file contains '%' percent characters. Cause
Field 6 of a crontab file entry holds the command to be
executed. In this field, a '%' character is used to indicate
the end of line, and text after the '%' is treated as stdin
information to be passed to the command.If a '%' occurs in a command argument, for example, a format
string for a date(C) command, it is translated into newline,
even if it is in quotes. The crontab(C) field 6 entrydate '+%T' >FOOactually results in no FOO file being created, but instead in the full date being written to stdout, and subsequently mailed to the user by cron.
Solution
The '\' backslash character can be used to escape the '%'
percent character in a crontab(C) file. Note however that
the escaping backslash is itself passed to the command in
whose argument it appears, so it may be necessary to exercise
some care in any quoting used.Following is an example of the use of '%' percent characters, both escaped and otherwise, in field 6 of a crontab(C) entry:
date +\%T >FOO; cat >>FOO%cfile line 1%cfile line 2This will create a file containing10:27:01
cfile line 1
cfile line 2Note that the date parameter +\%T is not quoted. If single
quotes are placed around this parameter, the first line of
the file becomes\10:27:01since the '\' is passed to date(C).