shell script to selectively tar directory based on date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script to selectively tar directory based on date
# 1  
Old 03-14-2008
shell script to selectively tar directory based on date

hye everybody Smilie ,
i'm new to the scripting world.. hope you guys can help me out with this one..

i'm trying to identify any directory under /tmp/saya that is created more than one day from the current date..

e.g, today is March 14, so any directory that has time stamp March 13 backwards, i want to tar it and put under /tmp/awak..

this is the script that i created (without the date)

### PART 1 : TO TAR FILE IN /tmp/saya AND PUT IN /tmp/awak ###
cd /tmp/saya
for file in *
do
if [[ -d $file ]]
then
tar -cvf /tmp/awak/$file.tar $file
fi
done


thanks a lot!
-fara
# 2  
Old 03-14-2008
Question Suggest you look into find

Code:
find . -mtime +1 -exec ls -l {}\;

that would list out the files older than one day
Therefore, you want to work that (or similar) into your process

Since you have the $file, maybe replace the . above with the $file?
# 3  
Old 03-16-2008
hi joeyg, thanks a lot! Smilie

this is what i did..

### PART 1 : TO TAR FILE IN /tmp/saya AND PUT IN /tmp/awak ###
cd /tmp/saya
for file in *
do
if [[ -d $file ]]
then
find . -mtime +1 -exec tar -cvf /tmp/awak/$file.tar $file {} \;
fi
done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Searching for a files based on current date directory

Hi All, I've been trying to do some recursive searching but not been very successful. Can someone please help. Scenario: I have directory structure /dir1/dir2/dir3/ 2019/ 11/ 17 18 19 20 so what I want to do is run a script and as its 2019/11/18/ today it would go and only search... (3 Replies)
Discussion started by: israr75
3 Replies

2. UNIX for Beginners Questions & Answers

Run shell script based on date file

Hi Team, I have a to run a script based on a date present in a different file which updates everyday. Kindly help with the solution. My current execution : ksh scriptname.sh 10152019. But here i want to enter this date from a file which gets updated daily. My appraoch : date file location:... (3 Replies)
Discussion started by: midhun3108
3 Replies

3. Shell Programming and Scripting

Tar with variable date in separate shell

Hi, I am trying to Zip a folder inside a shell script like below. It successfully taring but it only returns Null inside the variables. Searched a lot but no clue to finding the root cause. testno=1; date=20171128; DIR=/root/ sh -c 'cd $DIR; tar cvf "AWS.${testno.${date}.tar" "./AWS"' ... (5 Replies)
Discussion started by: pradyumnajpn10
5 Replies

4. UNIX for Dummies Questions & Answers

Creating a directory based on date

I want to create a directory based on date. I do not have date -d command. What I do have is: either use "date" command to get current date or DATE1=$(perl -e 'print scalar(localtime(time - 1 )), "\n";' |awk '{print $2,$3,$5}') |awk '{print $3}'can be modified to produce the desired year.... (3 Replies)
Discussion started by: newbie2010
3 Replies

5. Shell Programming and Scripting

Needed shell script to get the latest file based on date

hi i need the shell script to get the file with latest date. for example in my input folder i have files like file_20130212.txt file_20130211.txt now my output folder should have the file with latest date i.e..file_20120212.txt i want to get the latest file .. i.e is should take... (6 Replies)
Discussion started by: hemanthsaikumar
6 Replies

6. Shell Programming and Scripting

Moving files from one directory to another based on 2 date variables

Hi All, I am currently coding for a requirement(LINUX OS) where I am supposed to move a file (Lets Call it Employee.txt) from Directory A to Directory B based on 2 date fields as below, Date_Current = 20120620 Date_Previous = 20120610 Source Directory : /iis_data/source Target... (11 Replies)
Discussion started by: dsfreddie
11 Replies

7. Shell Programming and Scripting

How to FTP the latest file, based on date, from a remote server through a shell script?

How to FTP the latest file, based on date, from a remote server through a shell script? I have four files to be FTP'ed from remote server. They are of the following format. build1_runtime_mmddyyyy.txt build2_runtime_mmddyyyy.txt build3_runtime_mmddyyyy.txt buifile_count_mmddyyyy.txt ... (9 Replies)
Discussion started by: imran_affu
9 Replies

8. Shell Programming and Scripting

Need script to select multiple files from archive directory based on the date range

hi all, here is the description to my problem. input parameters: $date1 & $date2 based on the range i need to select the archived files from the archived directory and moved them in to working directory. can u please help me in writing the code to select the multiple files based on the... (3 Replies)
Discussion started by: bbc17484
3 Replies

9. UNIX for Dummies Questions & Answers

Using cp -r command to selectively omit *.dat files while copying a directory.

Hi all, I want to copy a directory named Ec1 to another directory named Ec2, newly created. But Ec1 has a bunch of *.dat files and many many other kinds of files. Whle creating Ec2, I selectively want to omit the *.dat files since they are huge files of the order of 100 MBs and there are... (5 Replies)
Discussion started by: d_sai_kumar
5 Replies

10. Shell Programming and Scripting

Shell script for Creating Directory with name as system date

Dear Sir/Madam, I need a bit of your help. The problem is as follows : I have to create a directory in unix whose name is that of system date in the dd_mon_yyyy format . I am able to extract a date in required format ina variable , but when i'm using this variable in mkdir it is not... (7 Replies)
Discussion started by: aarora_98
7 Replies
Login or Register to Ask a Question