List files with Date Range and Zip it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting List files with Date Range and Zip it
# 1  
Old 07-22-2010
MySQL List files with Date Range and Zip it

Hi all,

I am using the below script which display the files in the folder with the date range we specify. I want to add extra functionality that,

The listing files should be zipped using gzip. I tried to add exec gzip at the last line but it is not working.

Suggestions please.
Code:
#!/bin/ksh
  #################################################
  ## File: findDateRange.sh
  ## Purpose: A script to find the files within
  ## a given date range
  #################################################
  echo "You have to provide the path, start date and the end date"
  echo
  echo "Enter the path to start search"
  read fpath
  echo "Please enter the start date in the format YYYYMMDD"
  read strtdt
  echo "please enter the end date in the format YYYYMMDD"
  read enddt
  touch -t ${strtdt}0000 /tmp/newerstart
  touch -t ${enddt}2359 /tmp/newerend
  #find ./ \( -newer /tmp/newerstart -a \! -newer /tmp/newerend \) -print
  find $fpath \( -newer /tmp/newerstart -a \! -newer /tmp/newerend \) -exec ls -l {} \;

Instead of listing ls-l, i used gzip option but its not working.

Thanks in Advance.
# 2  
Old 07-22-2010
Try :
Code:
find $fpath \( -newer /tmp/newerstart -a \! -newer /tmp/newerend \) | xargs gzip

Jean-Pierre.
This User Gave Thanks to aigles For This Post:
# 3  
Old 08-01-2010
Hi Jean,

Thanks. Its working.

Is there any way to list only some particular file extensions. Instead of listing all.

Thanks in Advance.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (1 Reply)
Discussion started by: b.saipriyanka
1 Replies

2. UNIX for Beginners Questions & Answers

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (2 Replies)
Discussion started by: b.saipriyanka
2 Replies

3. UNIX for Dummies Questions & Answers

Find the count of files by last created date based on the given date range

My unix version is IBM AIX Version 6.1 I tried google my requirement and found the below answer, find . -newermt “2012-06-15 08:13" ! -newermt “2012-06-15 18:20" But newer command is not working in AIX version 6.1 unix I have given my requirement below: Input: atr files: ... (1 Reply)
Discussion started by: yuvaa27
1 Replies

4. UNIX for Advanced & Expert Users

Help with ksh script to list, then cp files from a user input date range

Hi, I'm quite new to ksh scripting, can someone help me with this. Requirements: I need to create a script that list the files from a user input date range. e. g. format of file: *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00*... (1 Reply)
Discussion started by: chococrunch6
1 Replies

5. UNIX for Dummies Questions & Answers

Help with removing files with date range

Hi, I want to remove trace files in a particular directory for a specific date range. Currently i can remove based on time (e.g find /path/*.trm -mtime +1000 -exec rm {} \;). But i want to remove .trm files within a date range. E.g to remove .trm files between jan 1 2002 to April 15 2005. ... (3 Replies)
Discussion started by: dollypee
3 Replies

6. Shell Programming and Scripting

Using 'date' to list a range of dates

Hi guys, I have been trying to create a list of dates from a certain range, ie. range from 01011950 to 31122000 But when my below code reaches certain dates, it comes up with a; 'date: invalid date 'yyyy-mm-dd -d 1day' Sofar I have come up with the following, slow and ugly; ... (4 Replies)
Discussion started by: TAPE
4 Replies

7. UNIX for Dummies Questions & Answers

How to list file names in a certain date range using ls command?

Hi experts, I Need to print file names in a certain date range using ls:confused:. Please help me with any sample script. Thanks a lot in advance. Regards, Satish (4 Replies)
Discussion started by: satish.vutti
4 Replies

8. Shell Programming and Scripting

Zip files by date

Hello, I need to create a bash script file that zip files. The obj is : the script enter into a directory, see all directories, and zip the files by date ( the script is for managment of logfiles ), exemple: in the directory there is just files following the name "ex090210" (yymmdd ), so i need... (1 Reply)
Discussion started by: joinup
1 Replies

9. UNIX for Dummies Questions & Answers

unzip .zip file and list the files included in the .zip archive

Hello, I am trying to return the name of the resulting file from a .zip archive file using unix unzip command. unzip c07212007.cef7081.zip Archive: c07212007.cef7081.zip SecureZIP for z/OS by PKWARE inflating: CEP/CEM7080/PPVBILL/PASS/G0063V00 I used the following command to unzip in... (5 Replies)
Discussion started by: oracledev
5 Replies

10. UNIX for Dummies Questions & Answers

cp only files in certain date range

hi all, I'm trying to do a cp only on files I created on a given day or within a certain date range. What's the best way to do this? Cheers, KL (1 Reply)
Discussion started by: ee7klt
1 Replies
Login or Register to Ask a Question