I encountered a strange problem in cron. According to crontab(5) man page, % has a special meaning in crontab commands. If used as it is, % is substituted with a new line. To preserve % in command line it has to be escaped with backslash. What I observe is that for every escaped % a character from the end of the command line is appended to it. For example, my crontab entry is: 27 13 * * * echo "\%a\%b 12345" This is converted into: Sep 7 13:27:00 fizia /USR/SBIN/CRON[1851]: (pike) CMD (echo "%a%b 12345"5") Looks strange, doesn't it? Am I hitting some known bug in cron? How can I use % without growing command line? This is SuSE 8.2, cron-3.0.1-701 Thanks, -Kastus
On Sun, Sep 07, 2003 at 06:40:28PM -0400, Doug McGarrett wrote:
Hey, I'm no Unix expert, but couldn't you put "%" in your code? I.E., use the quote morks to isolate the sign?
Unfortunately, it makes no difference to cron parser. When % sign stands by itself it is interpreted as new line and everything following it is fed as standard input to the command. When % character is escaped (\%) it should be passed as is to the command but crontab parser adds an extra character to the end of the command for each %. My original problem was that I wanted to use date command with format string from cron. E.g. date +\%Y-\%m-\%d It looks the only way to do it is to put it into a wrapper script. -Kastus
On Sun, Sep 07, 2003 at 06:40:28PM -0400, Doug McGarrett wrote:
Hey, I'm no Unix expert, but couldn't you put "%" in your code? I.E., use the quote morks to isolate the sign?
Unfortunately, it makes no difference to cron parser. When % sign stands by itself it is interpreted as new line and everything following it is fed as standard input to the command. When % character is escaped (\%) it should be passed as is to the command but crontab parser adds an extra character to the end of the command for each %. My original problem was that I wanted to use date command with format string from cron. E.g. date +\%Y-\%m-\%d It looks the only way to do it is to put it into a wrapper script. -Kastus
participants (5)
-
david stevenson
-
Doug McGarrett
-
Kastus
-
Kastus
-
Philipp Thomas