#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    7
    Rep 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...?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2007
    Posts
    44
    Rep Power
    11
    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 25th, 2011 at 12:22 AM.
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,997
    Rep Power
    481

    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.

IMN logo majestic logo threadwatch logo seochat tools logo