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

    Join Date
    Oct 2011
    Posts
    7
    Rep Power
    0

    Unhappy Write script for archieve


    Hi,
    I am new to shell scripting ..I need to planning to write a script ...the script ..the script will archive files in folder. All configuration should be done through a properties files...configuration file should ontain the details lyk..1) source folder name 2)2) file name pattern to archive... and the output should be Files are archived...plz guid e me how to write this script thanks in advance
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,442
    Rep Power
    1688
    How and where do you plan to this archive with and to? What, if any, requirements do you have for it's retrieval? Do you have any specific format for the configuration file and it's location?
    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
    Originally Posted by SimonJM
    How and where do you plan to this archive with and to? What, if any, requirements do you have for it's retrieval? Do you have any specific format for the configuration file and it's location?
    Hi ,

    I am sending the contents of the configuration file...and in the folder i want to extract all the XML files and make the tar and then send that tar in the output directory as mentioned in th configuration file....so the name of the configuration file is (backup.sh)..

    backup.sh(configuration file)
    *************************

    #!/bin/bash
    # backup files in here
    DIRTOBACKUP=/home/Administrator/files
    # tarballs get stored here
    TARDIR=home/Administrator/output
    # File containing patterns to save
    PATTERNFILE=/home/Administrator/scripts/patfile.sh
    # Kind of timestamp to use in the tar files
    TIMESTAMP="%F-%R" # yyyy-mm-dd-hh:mm



    and there is anothr script file which will be using the details from the configuration file that is ne1.sh and it contents are....

    (ne1.sh)
    ****************************

    #!/bin/bash
    #. ./home/admistrator/scripts/configration.sh

    # . /home/Administrator/scripts/app.properties
    . /home/Administrator/scripts/backup.sh


    # echo DIRTOBACKUP
    # echo TARDIR
    # echo PATTERNFILE
    # echo TIMESTAMP

    # prints an error message to stderr and quits.
    # ' [ something ] || die "message" ' quits with 'message' when something is false.
    # ' [ something ] && die "message" ' quits with 'message' when something is true.
    function die
    {
    echo "$0: $@" >&2
    exit 1
    }


    [ -f /home/Administrator/scripts/backup.sh ] || die "No config file" # check for config file
    [ -f "$PATTERNFILE" ] || die "No pattern file" # check for pattern file
    [ -d "$DIRTOBACKUP" ] || die "No input dir" # check for input dir
    [ -d "$TARDIR" ] || die "No archive dir" # check for archive dir
    [ -z "$TIMESTAMP" ] && die "No timestamp format" # need a time format

    # create a filename from today's date. See man date.
    TARFILE="backup_$(date "+${TIMESTAMP}").tar"

    # Find all files inside $DIRTOBACKUP.
    find "$DIRTOBACKUP" -type f |
    # Match things in $PATTERNFILE, excluding the rest.
    grep -f "$PATTERNFILE" |
    # Feed the filenames into tar via xargs.
    xargs -I {} | tar -rcf "${TARDIR}/${TARFILE}

    and the last is pattern file where I mentioned the pattern to extract all the xml files...it name is patfile.sh..and it contents are...

    patfile.sh
    *********

    #!/bin/bash
    \.xml$


    now the problem is upon executing I got the error that no pattern file ...plz giide me upon this or plz tell me some onother approch as I am stuck upon this..
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,442
    Rep Power
    1688
    If those are your actual files I'd have expected there to be issues based on the TARDIR:
    Code:
    # tarballs get stored here
    TARDIR=home/Administrator/output
    as you seem to have dropped the leading / from the path.

    Another thing:
    Code:
    [ -f /home/Administrator/scripts/backup.sh ] || die "No config file" # check for config file
    It seems a bit 'churlish' to do this test after actually having sourced the file!

    As you are sourcing the backup.sh file there is no need to have the shebang line (#!/bin/bash) at the start. Likewise you probably want to drop the shebang line from the patfile.sh:
    Originally Posted by man grep
    -f FILE, --file=FILE
    Obtain patterns from FILE, one per line. The empty file con-
    tains zero patterns, and therefore matches nothing.
    As to why you are getting the "No pattern file" message - I may have missed something but all the names look ok, so - does that file actually exist and does the user running the script have access to it?
    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