UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 19th, 2011, 03:55 AM
SANKALP SAX SANKALP SAX is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2011
Posts: 7 SANKALP SAX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 54 m 18 sec
Reputation Power: 0
Unhappy Script to move the files whith configurable days

Hi,

I am new to unix and was planning to write a script that will will move files which have a datetime >= currentdate-N from a source to destination folder. All configuration should be done through a properties files. In the form of input in the configuration fie the parameters would be

1) Configurable N days value(right now assume it as 10 days)
2) source folder
3) destination folder

and the final resultant would be The old files are moved, please guide me on this...thanks in advance..!!


the thing that I have tried for this one is......

find /basedir/sourcefolder -mtime +10 | xargs -I {} mv {} /basedir/destfolder

It will get the 10 days older files and move the files from one location to another.
you can get 10 as argument or read from the file..but still it is not that the above configuration file that I want ...could you please guide me on this ..!!

Reply With Quote
  #2  
Old October 19th, 2011, 07:51 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,107 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 3 h 57 m 31 sec
Reputation Power: 1485
As it stands that will move files as well as directories - is that want you want? If it is jusrt files add a -type f to the find parameters. As for the variable number of days ... replace the literal 10 with that of a variable that holds the value read from your configuration file (or a suitable default if no value found).
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc

Reply With Quote
  #3  
Old October 19th, 2011, 09:33 AM
SANKALP SAX SANKALP SAX is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2011
Posts: 7 SANKALP SAX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 54 m 18 sec
Reputation Power: 0
show the complete structure

Quote:
Originally Posted by SimonJM
As it stands that will move files as well as directories - is that want you want? If it is jusrt files add a -type f to the find parameters. As for the variable number of days ... replace the literal 10 with that of a variable that holds the value read from your configuration file (or a suitable default if no value found).


Hi SimonJM,

Thanx a lot ,I request you if you can show me how to read the valuse from the configuraton file itself in detail with the structure of configuration file plus main script file ...!!

Reply With Quote
  #4  
Old October 19th, 2011, 01:55 PM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,107 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 3 h 57 m 31 sec
Reputation Power: 1485
It all depends on what you have, if anything, what you want and need in terms of usability (both in this script and also with any update function you may wish for).
A very simple way is to parse the config file using grep, looking for the keywords and then awk (or cut) to pull out the value. So, if your config file contained DAYS=8 on one line, you could use something like:
Code:
days=$(grep "^DAYS=" your_config_file | awk -F= '{print $2}')
days=${days:=10}

which would pull out the value in the config file, if found, and then assign a default value (of 10) if not value was found.
The location of the config file would be, of course, up to you and the script would also handle it not being found in a manner you decided - maybe by letting it fall through and use all the default values.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Script to move the files whith configurable days

Developer Shed Advertisers and Affiliates



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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap