Reputation: 17
I'm trying to append the current date and time to a log file every minute using cron. I want the date and time to be formatted in a specific way.
This works:
* * * * * date >> /home/user/time1.txt
This doesn't:
* * * * * date +%Y%m%d%H%M%S >> /home/user/time2.txt
Any insight is much appreciated!
Upvotes: 0
Views: 75
Reputation: 85590
The problem is that cron
treats %
as newlines. You need to escape them
From crontab POSIX man
page:
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.
* * * * * date +\%Y\%m\%d\%H\%M\%S >> /home/user/time2.txt
Upvotes: 2