Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Cron to copy and append date to .html file

Posted on 1998-09-16
14
Medium Priority
?
297 Views
Last Modified: 2010-04-21
I've written a cron to do the following:
Copy my analog.html file from one dir to another and saving the analog.html file with the date appended. As such 091698_analog.html. Here's what I have so far.
cp $dir1/analog.html $dir2/'date'+%m%d%y''_$analog.html
It does copy the file to the new dir but the file name ends up as %m%d%y_analog.html
What can I change to ensure the date is appended to the file name?
Any help appreciated
Thanks =PC=
0
Comment
Question by:smelt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
14 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2006994
cp $dir1/analog.html $dir2/`date '+%m%d%y'`_analog.html
0
 

Author Comment

by:smelt
ID: 2006995
Actually I tried this first and the file name returned as just _analog.html  No Date
Any other suggestions?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2006996
did you try full pathnames?

cp $dir1/analog.html $dir2/`/bin/date '+%m%d%y'`_analog.html
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:smelt
ID: 2006997
Yes, I've tried full path.
This is what I have:
cp $ /home/httpd/html/analog/analog.html $ /home/httpd/html/analog/backup/`date '+%m%d%y'`_analog.html

Do I need to run the date first? It seems like it's not running the date, just appending the %m%d%y to the filename. I've tried the date %m%d%y from the command line and it runs as it should.
Running Red Hat Linux release 5.1 (Manhattan)    

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2006998
what are the  $  (dollar) signs iin your cp command for ?

date enclosed in backtics (graves) should work.

Is your command in crontab, or does crontab call a script to
do this? If it is a script, which shell is used?
0
 

Author Comment

by:smelt
ID: 2006999
Currently the command is in crontab.
I've tried with and without the {$}
I'll try the (date)enclosed and see what happens.

0
 

Author Comment

by:smelt
ID: 2007000
I tried the (date) and no go.
Basically I need to ensure that the file would be copied to the new dir with a name change so as not to copy over an existing analog.html file. I'd like to keep a running log so that I can compare. Even if it were some sort of incremental routine so that the file is copied and named 1_analog.html and the next time cron runs it names it 2_analog.html
Is there another way other than date?
0
 
LVL 3

Accepted Solution

by:
junfeb earned 800 total points
ID: 2007001
Try this -
cp tmp/analog.html tmp1/`date +'%m%d%y'`_analog.html
 
here tmp and tmp1 are two directories

cp tmp/analog.html tmp1/(backquote)date (space)+(singlequote)%m%d%y(singlequote)(backquote)_analog.html.

This would create a file named
091798_analog.html

I hope this is what you want.

Thanks.
0
 

Author Comment

by:smelt
ID: 2007002
Thanks It works.
I'm happy:)
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2007003
Hmm, I can't see any difference between junfeb's answer and mine,
except that the + is not inside the quotes (which should not make
a difference.
Could you please explain?
0
 

Author Comment

by:smelt
ID: 2007004
I did try the + inside the quotes. It did not work. I've tried many times with quotes, without, spacing, brackets. It just so happens that junfebs' response worked.
Initially my first attempt was the same as junfebs but the quote was on the wrong side of the + sign...
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2007005
Whis OS are you using?
0
 

Author Comment

by:smelt
ID: 2007006
Red Hat Linux release 5.1 (Manhattan)   It Rocks!
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2007007
Strange.
Could you test with another shell (which one do you have?).

I'm just wondering.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question