Script to move files to a directory according to date
hi all,
here is the description to my problem.
input parameter: $date1
based on the date i need to select three files starting with audit.log* based on its modified date, a date before, a date after(if its exists). We need to compare the input date to modified date of the file. And then move these three files to a directory.
can u please help me in writing the code to select the multiple files based on the date input.
An example of how a ls -lrt looks like.
-rwx--r--r oracle oinstall 4354334 Aug 24 10:13 ois_audit.log.20110824.3445543.9090899
When i do a ls --full-time
I can give date1 in any format i like. I can mention it as MMDDYYYY
Can you explain how the code works...
do i have to save the first code in a separate file called date1 and export it?
Also it does not have a (date1+1)next day.
Proposal: Give date1 as "YYYY-MM-DD HH:MM". The script would then be called as:
(if such precision not necessary, simply drop the HH:MM) and contains:
What it does is to convert the date argument ($1) to seconds-since-epoch format
pass it as environment variable date1 inside the awk script,
which receives the output from the ls command as standard input.
The second-to-last column contains the file modification time as seconds-since-epoch
(epoch = 1970-01-01 00:00 GMT), the last column contains the filename.
These two columns are taken, from the timestamp the absolute difference
to your date argument (converted to seconds-since-epoch) is calculated,
so first column contains this absolute time difference, the second one the filename.
Then it is numnerically sorted according to the first column, i.e. the filenames with
the three smallest time differences appear in the first three lines, which are taken
by "head -n 3" and then only the second column of these three lines is taken
by "cut" to stay only with the filenames.
Finally you may add the following two lines to the script
in order to create a directory with a unique name and copy the files to it:
I have a script, which is checking if file exists and move it to another directory
if
then
mkdir -p ${LOCL_FILES_DIR}/cool_${Today}/monthly
mv report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv ${LOCL_FILES_DIR}/cool_${Today}/monthly
... (9 Replies)
Hi All,
We have main directory called "head"
under this we have several sub directories and under these directories we have sub directories.
My requirement is I have to find the SQL files which are having the string "procedure" under "head" directory and sub directories as well.
And create... (14 Replies)
Hi All,
Daily i am doing the house keeping in one of my server and manually moving the files which were older than 90 days and moving to destination folder.
using the find command . Could you please assist me how to put the automation using the shell script .
... (11 Replies)
Hi all,
i have a folder, with tons of files containing as following,
on /my/folder/jobs/
some_name_2016-01-17-22-38-58_some name_0_0.zip.done
some_name_2016-01-17-22-40-30_some name_0_0.zip.done
some_name_2016-01-17-22-48-50_some name_0_0.zip.done
and these can be lots of similar files,... (6 Replies)
Hi,
need to zip all files in a directory and move to another directory after the zip..
i am using this one but didnt help me...
zip -r my_proj_`date +%Y%m%d%H%MS`.zip /path/my_proj
mv in_proj_`date +%Y%m%d%H%M%S`.zip /path/source/
i am trying to zip all the files in my_proj... (0 Replies)
Hi All,
Really stuck up with a requirement where I need to move a file (Lets say date_Employee.txt--the date will have different date values like 20120612/20120613 etc) from one directory to another based on creation/modification dates.
While visiting couple of posts, i could see we can... (3 Replies)
Hi All,
I am trying to to move files from a directory to another which falls from Current day - 7 days. The files are in zipped format with dates appended on it.
Can you pls help me as this came as a immediate change before the production Release planned next week.
Pls let me know if... (11 Replies)
Hi Team,
I have thousands of TIF files which are converted from PDF. Below is a sample of it.
LH9406_BLANCARAMOS_2012041812103210320001.tif
LH9406_BLANCARAMOS_2012041812103210320002.tif
LH9406_BLANCARAMOS_2012041812103210320003.tif
LH9411_ANGENIAHUTCHINSON_2012041812102510250001.tif... (9 Replies)
Is this possible? Let me know If I need specify further on what I am trying to do- I just want to spare you the boring details of my personal file management.
Thanks in advance-
Brian- (2 Replies)