writing the main script file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting writing the main script file
# 1  
Old 10-22-2011
writing 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:
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:
#############################################

#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...?Smilie
# 2  
Old 10-22-2011
Code:
awk -F = '/Days=/{days=$2}/SrcDirectory=/{src=$2}/DestDirectory=/{dest=$2}END{print days, src, dest}' archive.config  |while read DAYS INDIR OUTDIR
do 
    find $INDIR -type f "!" -mtime $DAYS -exec mv {} $OUTDIR \;
done

This User Gave Thanks to rdcwayx For This Post:
# 3  
Old 10-22-2011
Quote:
Originally Posted by rdcwayx
Code:
awk -F = '/Days=/{days=$2}/SrcDirectory=/{src=$2}/DestDirectory=/{dest=$2}END{print days, src, dest}' archive.config  |while read DAYS INDIR OUTDIR
do 
    find $INDIR -type f "!" -mtime $DAYS -exec mv {} $OUTDIR \;
done

Hi,
Thanks a lot for the guidance, I request you if you could also please explain a little bit about your main script also..Thanks in advance..!!Smilie
# 4  
Old 10-22-2011
Try this...
Code:
. ./archive.config
find $SrcDirectory -type f "!" -mtime $Days -exec mv {} $DestDirectory \;

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 5  
Old 10-22-2011
Quote:
Originally Posted by ahamed101
Try this...
Code:
. ./archive.config
find $SrcDirectory -type f "!" -mtime $Days -exec mv {} $DestDirectory \;

--ahamed

Hi Ahamed,

Thanks a lot, I request you if you could please expain a liitle bit about this script functionality ...Thanks in advance..!!
# 6  
Old 10-22-2011
Following piece of code is what is known as sourcing...
Code:
. ./archive.config

Once you sourc the file, all the parm=val will be available in the current shell...
So if you echo the param in the current shell you will get the value...
Code:
echo $Days
10

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 7  
Old 10-22-2011
movinfg files ap per modification days in not functioning

Hi,
this code is working perfectly...seen below...

Code:
awk -F = '/Days=/{days=$2}/SrcDirectory=/{src=$2}/DestDirectory=/{dest=$2}END{print days, src, dest}' archive.config  |while read DAYS INDIR OUTDIR
do 
    find $INDIR -type f "!" -mtime $DAYS -exec mv {} $OUTDIR \;
done


this script reads the properties file shown below...
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=2

but here the ndays values is set to 2 and the above main script move all the files, but it should only move the file which are modified within 2 days in the output folder from the files folder...please guide on this...!!thanks in advance
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help Writing File Restore Script

Hi all, I have been tasked with creating a script that sends a file into a created "recycling" directory and another script that restores a "deleted" file. I have already created the removal script but am stuck on the restoring part. I need to restore the file to its original location by... (0 Replies)
Discussion started by: bashbeginner
0 Replies

2. UNIX for Dummies Questions & Answers

Writing a script that will take the first line from each file and store it in an output file

Hi, I have 1000 files names data1.txt through data1000.txt inside a folder. I want to write a script that will take each first line from the files and write them as output into a new file. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

3. Shell Programming and Scripting

Need help in writing a script to edit a file

Hi all, I need help in writing a script to edit a file Here is the sample of my file abc xxx 123 456 789 045 def yyy 987 678 098 cdf zzz 435 543 jhg vvv 987 765 (2 Replies)
Discussion started by: leo.maveriick
2 Replies

4. Shell Programming and Scripting

Help with writing shell script file

I am trying to prompt the user using tput command to read the information ( 5 last names, first names and grades) from the keyboard. Save the data in a file called student.txt. Sort the file by last name and display it on the screen My pseudocode is as follow: Pseudocode: Initialize... (1 Reply)
Discussion started by: jestaton
1 Replies

5. UNIX for Dummies Questions & Answers

Help writing a script to find a file

I just started learning about Unix and I cant figure out what im doing wrong. I'm trying to write a script that will ask for the file name and tell what type it is. This is what i have so far. http://i63.photobucket.com/albums/h123/wacand/untitled.jpg (2 Replies)
Discussion started by: wacand
2 Replies

6. UNIX for Dummies Questions & Answers

HELP! writing shell script with c++ file

how would i write a shell script to count number of one-line comments in a c++ file. please help with coding thank you. (1 Reply)
Discussion started by: deadleg
1 Replies

7. Shell Programming and Scripting

script for writing to a file

Hi, Can some some give ideas/help how to write to a file. i need to create a calender from the inputs given on command line i.e frm date,todate & -i is interval is given to write to a file. -i is 1 then a calender is daily , if -i =2 then calender is alternate day e.g $1 ... (0 Replies)
Discussion started by: innocent
0 Replies

8. Shell Programming and Scripting

writing script file for database

how to disable a constraint type of a field (present in diffrent tables) in the database unix a unix script file.. (3 Replies)
Discussion started by: shaksing
3 Replies

9. Shell Programming and Scripting

Writing to a file within a script

Hi, At the moment i have a script where it asks the user if they want to create a file and what to put in the file. The problem is when the script is run the user inputs the information, though when they are finished typing what they want to be in the file there is no way for the program to know... (3 Replies)
Discussion started by: Jaken
3 Replies

10. UNIX for Dummies Questions & Answers

help writing script file

Does anyone know how I can write a script file that reads 15 numbers and can find the average, maximum and minimum of the 15 numbers. I'm new to UNIX 1 month into it, and (no) this is not for homework. I'm reading UNIX unbounded and trying the practice questions and I've been working on... (19 Replies)
Discussion started by: lanboy_2005
19 Replies
Login or Register to Ask a Question