Grep date pattern folder and zip -->delete


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep date pattern folder and zip -->delete
# 1  
Old 10-16-2018
Grep date pattern folder and zip -->delete

Hi All,

OS: Redhat Linux 7.5
Shell: Bash

I have some folder like this

Code:
2018-09-16
 2018-09-17
 2018-09-18
 2018-09-19

and so on...

Everyday one script create a folder with pattern YYYY-MM-DD (it will have so many sub directories files in it)

Now what I would like to achieve is a cron job should run every day 7 AM then it should check for previous day folder then zip it(tar.gz) with same name and delete the folder once tar is created successfully..

for example: if cron running on 2018-10-16 then it should find folder called 2018-10-15 --> tar it like tar -zcvf 2018-10-15.tar.gz 2018-10-15 --> then delete rm -rf of that 2018-10-15 folder

though i have clear cut of idea of step, finding difficult to list previousday folder by searching pattern...please help

Moderator's Comments:
Mod Comment Code tags please

Last edited by jim mcnamara; 10-16-2018 at 09:50 AM..
# 2  
Old 10-16-2018
We are not a coding service, but your date command does this for you:
Code:
# example using date command to find yesterday
date -d yesterday "+%Y-%m-%d"
2018-10-15
# do this make two files with known dates -one way to search
# start of yesterday:
 touch -t $(date -d yesterday "+%Y%m%d0000") start.tmp
# end of yesterday
 touch -t $(date -d yesterday "+%Y%m%d2359") end.tmp
# assume only one directory
 mydir=$(find /path/to/files  -type d ( -newer start.tmp -a  ! -newer end.tmp) )
# you need to code your tar solution here using the mydir variable here:
#
#
rm start.tmp end.tmp

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Grep a pattern from zip file which has multiple files insdie

Hi Gurus, I got a small requirement in my script to grep a specific pattern in a zip compressed file which has been created with multiple files. Sample File: 20180913.zip $> zipinfo -l 20180913.zip 20180913_file1 20180913_file2 20180913_file3 20180912_file4 20180912_file5... (1 Reply)
Discussion started by: hi.villinda
1 Replies

2. Shell Programming and Scripting

Delete oldest folder based on folder named as date

Hi, I have a script doing backup to synology server, the script create new folder each day with the date as being folder name i.e. 2018-07-30. Just before creating the new folder I want the script to find the oldest folder from the list and delete it including its content. for example... (3 Replies)
Discussion started by: humble_learner
3 Replies

3. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

4. 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

5. 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

6. Shell Programming and Scripting

sed and awk usage to grep a pattern 1 and with reference to this grep a pattern 2 and pattern 3

Hi , I have a file where i have modifed certain things compared to original file . The difference of the original file and modified file is as follows. # diff mir_lex.c.modified mir_lex.c.orig 3209c3209 < if(yy_current_buffer -> yy_is_our_buffer == 0) { --- >... (5 Replies)
Discussion started by: breezevinay
5 Replies

7. Shell Programming and Scripting

Grep a pattern in current date logs

Hello, I need to write one script which should search particular pattern like ABCD in log file name hello.txt only in current date logs. in current directory i have so many past date logs but grep should be applied on current date logs. on daily basis current date logs are in number 30 and... (2 Replies)
Discussion started by: ajju
2 Replies

8. UNIX for Dummies Questions & Answers

Zip command (zip folder doesn't include a folder of the same name)

Hi guys, I have a question about the zip command. Right now I have a directory with some files and folders on it that I want to compress. When I run the zip command: zip foo -r I am getting a foo.zip file that once I unzip it contains a foo folder. I want to create the foo.zip, but that... (1 Reply)
Discussion started by: elioncho
1 Replies

9. Windows & DOS: Issues & Discussions

How can I upload a zip folder on a unix path from my windows folder?

Hello, I am an amature at UNIX commands and functionality. Please could you all assist me by replying to my below mentioned querry : How can I upload a zip folder on a unix path from my windows folder? Thanks guys Cheers (2 Replies)
Discussion started by: ajit.yadav83
2 Replies

10. UNIX for Dummies Questions & Answers

How can i delete files in folder by date?

Hi, I have some files on a folder and i want to delete all the files that were created on July. Thanks, Kobi. (9 Replies)
Discussion started by: kobibn
9 Replies
Login or Register to Ask a Question