Crontab ignoring $(date +%F_%T) output filenaming

washy16
washy16 used Ask the Experts™
on
I'm trying to get cron to output to a file with the current date/time in it, but I'm getting EOF errors mailed to me. If I enter the full command on the command line, it works perfectly.

Here is an example to make it a bit clearer:

10 * * * * find / -perm -u=s 1> /root/$(date +%F_%T)_SUID

Any help would be greatly appreciated.

Thanks,

W.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2013
Top Expert 2013
Commented:
Hi,

that's a feature of cron - youll have to escape the percent signs using a backslash ( \% ),
because cron makes anything following a percent sign available as stdin data to the command.

10 * * * * find / -perm -u=s 1> /root/$(date +\%F_\%T)_SUID

wmp


Top Expert 2007
Commented:
From the crontab manpage

      The  ``sixth''  field (the rest of the line) specifies the command to be run.  The entire command portion of the line, up to a newline or % character, will be
       executed by /bin/sh or by the shell specified in the SHELL variable of the crontab file.  Percent-signs (%) in the command, unless escaped with backslash (\),
       will  be changed into newline characters, and all data after the first % will be sent to the command as standard input. There is no way to split a single com-
       mand line onto multiple lines, like the shell's trailing "\".

Author

Commented:
@ woolmilkporc:  Thanks a lot. That would perfectly.

@tintin: I read the man pages more than once. I can't beleive I missed that part. Thanks!

Author

Commented:
typo in previous comment: would = worked  :)

Thanks again!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial