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

    Join Date
    Oct 2011
    Posts
    7
    Rep 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 ..!!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,437
    Rep Power
    1688
    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
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    7
    Rep Power
    0

    show the complete structure


    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 ...!!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,437
    Rep Power
    1688
    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.
    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

IMN logo majestic logo threadwatch logo seochat tools logo