The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using cp -r command to selectively omit *.dat files while copying a directory. d_sai_kumar UNIX for Dummies Questions & Answers 5 07-18-2008 06:48 AM
Selectively splitting a file with C-shell? fusi0n Shell Programming and Scripting 2 12-11-2007 05:06 PM
Specify a previous date as start date in shell script ritzwan0 Shell Programming and Scripting 2 09-25-2006 05:58 PM
Shell script for Creating Directory with name as system date aarora_98 Shell Programming and Scripting 7 12-07-2005 08:14 AM
script to view files based on date krahuliyer Shell Programming and Scripting 6 10-05-2005 04:51 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-14-2008
fara_aris fara_aris is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 27
shell script to selectively tar directory based on date

hye everybody ,
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 (permalink)  
Old 03-14-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
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 (permalink)  
Old 03-16-2008
fara_aris fara_aris is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 27
hi joeyg, thanks a lot!

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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0