LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-12-2010, 09:11 AM   #1
craigjl
LQ Newbie
 
Registered: Mar 2010
Posts: 2

Rep: Reputation: 0
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
 
Old 03-12-2010, 09:15 AM   #2
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 12.04 / CentOS 6.5
Posts: 384

Rep: Reputation: 61
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?

Last edited by arashi256; 03-12-2010 at 09:17 AM.
 
Old 03-12-2010, 09:19 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

Cron sees the % as being special, you need to escape it (\%).

Hope this helps.
 
1 members found this post helpful.
Old 03-12-2010, 09:29 AM   #4
jwl17330536
Member
 
Registered: Feb 2010
Location: Raleigh, NC
Posts: 83

Rep: Reputation: 22
Or simply put the command in a script and execute the script every minute.
 
Old 03-12-2010, 09:34 AM   #5
craigjl
LQ Newbie
 
Registered: Mar 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Excellant! Problem Solved

Quote:
Originally Posted by druuna View Post
Hi,

Cron sees the % as being special, you need to escape it (\%).

Hope this helps.
Changed my original line:
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
 
Old 03-12-2010, 09:46 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
You're welcome
 
  


Reply

Tags
date, touch


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to rename a file based on it creation date limdel Linux - Newbie 11 09-23-2009 06:41 AM
delete a file based on content and date ElectroLinux Linux - Newbie 7 08-19-2009 07:01 AM
shell script to find modified date and last accessed date of any file. parasdua Linux - Newbie 6 04-22-2008 09:59 AM
Bash: date based file maintenance paul.anderson Programming 4 07-19-2006 06:23 AM
howto create a file based on date in bash rohan208 Linux - Newbie 2 05-07-2004 03:54 PM


All times are GMT -5. The time now is 05:18 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration