Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Copy Question 1

Status
Not open for further replies.

TheRAt

Technical User
Jul 19, 2000
155
NZ
Hi.

I have a cron job that downloads some information from the net @ 02:20 every weekday and stores this on the machine as XXYY.dat, where XXYY is the date in in the format MMDD.

As part of a separate process, much later, I need to copy this file and name it as follows:

XXYY.dat.YYYYMMDD-hhmm

XXYY - original name
YYYY - year (ie. 2001)
MM - month (12)
DD - date (18)
hh - hour (15)
mm - minute (03)

I have tried the following:

/bin/cp -v /download/????.dat /backup/????.dat.`date +%Y%m%d-%H%m`

But this results in a filename with ?'s...

If someone can correct my script, or point me in the direction of some instructions on getting this to work, it would be very much appreciated. AV
tnedor@yahoo.com

Did this post help? Click below to let me know.
 
One way to do it might be like this:

presto() {
f=$1
#split the date into elements
yr=`date +%?`
month=`date +%?`
day=`date +%?`
hr=`date +%?`
min=`date +%?`

format="$1.$yr$month$day$hr$min"
cp $1 $format
return $?
}

another way I was trying it was with awk, but I cannot
get all the info you want from strftime(). It was a lot
of fun to write. ;-)

Hope this helps you.





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top