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 22nd, 2011, 05:05 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
Completeing the main script file ...

Hi,

I am new to shell scripting,and i was planning to write a script that will move files which have a datetime >= currentdate-N from a source to destination folder. All configuration should be done through a properties files.

Here the value of N should be taken as 10 days(modification time)and finally the output is files are moved.

I have developed a properties file named tar_config_file1.sh and the content of this file are...



Code:

Code:
10   /home/Administrator/files  /home/Administrator/output


here 10 represents 'N' DAYS , and files is the folder from where files will be picked up and output is the folder where the finally the filles will be moved.

my main script file named main1.sh which will read the properties file(tar_config_file1.sh) contents are...



Code:
#!/bin/sh
while read DAYS INDIR OUTDIR
do
find $INDIR -type f "!" -mtime $DAYS -exec mv {} $OUTDIR \;
done </home/Administrator/scripts/tar_config_file1.sh


Now I want to change the structure of my properties file(archive.config) in the below format...




Code:
Code:
#############################################

#Properties file for moving files

#############################################

#This is the source directoy from where the files will be picked up
SrcDirectory=/home/Administrator/files


#This directory path should end with a slash(/)
DestDirectory=/home/Administrator/output/


#Configurable N days value is assumed here of 10 days
Days=10


Now how I will change my main scipt file...That is how my main script file will read this new properties file ...


Code:
#!/bin/sh
src_dir=$(sed '/^\#/d' archive.config | grep 'SrcDirectory'  | tail -n 1 | cut -d "=" -f2-)
dest_dir=$(sed '/^\#/d' archive.config | grep 'DestDirectory'  | tail -n 1 | cut -d "=" -f2-)
ndays=$(sed '/^\#/d' archive.config | grep 'Days'  | tail -n 1 | cut -d "=" -f2-)


Could you please guide me on this main file How I would write the full script of the main File as I have done earlier...?

Reply With Quote
  #2  
Old October 24th, 2011, 11:20 PM
Bardon Bardon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 44 Bardon User rank is Corporal (100 - 500 Reputation Level)Bardon User rank is Corporal (100 - 500 Reputation Level)Bardon User rank is Corporal (100 - 500 Reputation Level)Bardon User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 3 h 48 m 15 sec
Reputation Power: 9
Quote:
Originally Posted by SANKALP SAX
Hi,

I am new to shell scripting,and i was planning to write a script that will move files which have a datetime >= currentdate-N from a source to destination folder. All configuration should be done through a properties files.

Here the value of N should be taken as 10 days(modification time)and finally the output is files are moved.

I have developed a properties file named tar_config_file1.sh and the content of this file are...



Code:

Code:
10   /home/Administrator/files  /home/Administrator/output


here 10 represents 'N' DAYS , and files is the folder from where files will be picked up and output is the folder where the finally the filles will be moved.

my main script file named main1.sh which will read the properties file(tar_config_file1.sh) contents are...



Code:
#!/bin/sh
while read DAYS INDIR OUTDIR
do
find $INDIR -type f "!" -mtime $DAYS -exec mv {} $OUTDIR \;
done </home/Administrator/scripts/tar_config_file1.sh


Now I want to change the structure of my properties file(archive.config) in the below format...




Code:
Code:
#############################################

#Properties file for moving files

#############################################

#This is the source directoy from where the files will be picked up
SrcDirectory=/home/Administrator/files


#This directory path should end with a slash(/)
DestDirectory=/home/Administrator/output/


#Configurable N days value is assumed here of 10 days
Days=10


Now how I will change my main scipt file...That is how my main script file will read this new properties file ...


Code:
#!/bin/sh
src_dir=$(sed '/^\#/d' archive.config | grep 'SrcDirectory'  | tail -n 1 | cut -d "=" -f2-)
dest_dir=$(sed '/^\#/d' archive.config | grep 'DestDirectory'  | tail -n 1 | cut -d "=" -f2-)
ndays=$(sed '/^\#/d' archive.config | grep 'Days'  | tail -n 1 | cut -d "=" -f2-)


Could you please guide me on this main file How I would write the full script of the main File as I have done earlier...?



I may be missing something very basic, but why don't you just source the archive.config file as the first action in your script? IE let's say that archive.config lives in a fictional directory called /myconfigs...

Code:
#!/bin/sh
. /myconfigs/archive.config
find $SrcDirectory -type f "!" -mtime $Days -exec mv {} $DestDirectory \;


This will action archive.config inline in your current script, therefore setting the variable SrcDirectory=/home/Administrator/files etc.

IMPORTANT NOTE: The space between the initial '.' and the filename for archive.config is vital!

Edit: Unless you mean to have multiple sets of Source, Destination and Days processed in one run of the same script, in which case it's more complicated.

Last edited by Bardon : October 24th, 2011 at 11:22 PM.

Reply With Quote
  #3  
Old October 25th, 2011, 07:07 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,368 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 11 h 22 m 4 sec
Reputation Power: 383
sourcing

http://www.gnu.org/software/bash/manual/bashref.html#Bourne-Shell-Builtins

I suspect the original poster didn't use it because the original poster was unaware.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Completeing the main script file ...

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