Use date with touch to create new file with date based name
I am using CRON to create a new, blank file, every minute, in a specific location on my web server. After web searching, and reading man pages, I get the impression that the following command is supposed to work:
touch /home/mydomain/var/folder/attachments/`date +%H%M`.txt This should give me a new file with a file name that is the current hour and minute. However, when executed, the CRON mailer reports: touch /home/mydomain/var/folder/attachments/`date + /bin/sh: -c: line 0: unexpected EOF while looking for matching ``' /bin/sh: -c: line 1: syntax error: unexpected end of file So, it looks like shell is seeing the plus (+) sign as an EOF Obviously, nothing get created. What would be the easiest, single line command to create an empty file, at a given location, with a time based file name? Jim Craig |
That command works fine for me. Have you tried simply running that command from the commandline? If so, and it works, what does your crontab entry look like?
|
Hi,
Cron sees the % as being special, you need to escape it (\%). Hope this helps. |
Or simply put the command in a script and execute the script every minute.
|
Excellant! Problem Solved
Quote:
touch /home/mydomain/var/folder/attachments/`date +%H%M`.txt to: touch /home/mydomain/var/folder/attachments/`date +\%H\%M`.txt And everything just works now! I figured something had to be escaped, but wasn't sure. Will have to read up on CRON a little more. Thanks for the quick solution. Jim Craig |
You're welcome ;)
|
All times are GMT -5. The time now is 08:21 AM. |