Operating System - HP-UX
1838671 Members
6088 Online
110128 Solutions
New Discussion

Re: Moving files to another dir and add the current date

 
SOLVED
Go to solution
Patrick Zeitz
Occasional Contributor

Moving files to another dir and add the current date

Hi all,

i'm trying to moving files from one dir to another with a cron job.
In dir /fibu/prod/log/ are some logs saved and numbered from 000 to 999. I want to archive them in a special folder /fibu/arch/ by adding the date in front of the filename.

mv /fibu/prod/log/transferlog.* /fibu/arch/$(date +$y$m$d)*

But so there will be one file (theres today only one in the log dir) moved and renamed to 020429*

Any ideas? Thanks
Patrick
6 REPLIES 6
Paula J Frazer-Campbell
Honored Contributor

Re: Moving files to another dir and add the current date

Hi Patrick

1. Move them.
2. Tar them into one file.
3. Gzip the file and add the date to its name.

HTH

Paula
If you can spell SysAdmin then you is one - anon
Patrick Zeitz
Occasional Contributor

Re: Moving files to another dir and add the current date

The files will be needed one month unziped. And in this period it's possible that there will be more than 1.000 logs...
Do you know how i can avoid that a * will be used in the new filename?

Patrick
Deepak Extross
Honored Contributor
Solution

Re: Moving files to another dir and add the current date

Write a small script like this:

#!/usr/bin/ksh
cd /fibu/prod/log
for x in *
do
y=`date '+%y%m%d'`
mv $x /fibu/arch/$y$x
done

Then call this script form your crontab.

Hope this helps.
Niraj Kumar Verma
Trusted Contributor

Re: Moving files to another dir and add the current date

Hi you this following script

#!/bin/sh

Source_Dir="/fibu/prod/log"
Dest_DIr="/fibu/arch"
Date_Stamp=`date '+%b-%d-%Y'`

cd $Source_Dir

for index in `ls -l |awk '{print $9}'`
do
mv $index $Dest_DIr/$index.$Date_Stamp

done


-Niraj
Niraj.Verma@philips.com
John Carr_2
Honored Contributor

Re: Moving files to another dir and add the current date

Hi

try using a shell script something like this will do it.

#!/usr/bin/ksh

for filename in /fibu/prod/log/transferlog.* ; do

newdate=$(date +%m%d%y)
newfilename=$(print $filename$newdate)

mv $filename $newfilename

done

John.
Patrick Zeitz
Occasional Contributor

Re: Moving files to another dir and add the current date

You where are all great.
Now it works, thanks a lot.

Patrick