#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    4
    Rep Power
    0

    Exclamation help in creating script to make tar file


    hello, im a newbie in unix scripting. can someone pls send me a sample script that will tar files in the folders of a specific directory, but will exclude specific files, and afterwards, will ftp the tar into another server.

    for example:
    in this directory, pshrprod:/opt/psoft/weblogic/818sp9_80

    the following files and folders will be tar'd (this are not all the files/folders in this directory)

    copyright.html
    license.txt
    license.html
    classes --this folder also has files inside--
    src

    but will exclude these files in these directories:

    Please exclude (aonprod08)pshrprod:/opt/psoft/weblogic/818sp9_80/psftaccess.log and /opt/psoft/weblogic/818sp9_80/myserver/access.log

    my question is: if the files will be tar'd where will the tar file be located?

    also, can the specific date and time of the run of the script be included?

    hope someone out there replies to me ASAP.

    thanks a lot
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    137
    Rep Power
    0

    Re: help in creating script to make tar file


    send me a sample script that will tar files in the folders of a specific directory, but will exclude specific files, and afterwards, will ftp the tar into another server.
    The --exclude-from=FILE option that is part of tar is one option.

    $ tar cf some.tar --exclude-from=/some/path/exclude_me *

    This will tar all (* at the end) except for the files mentioned in/home/joe/exclude_me. Under unix/linux, the term 'files' also include directories.

    So if you put these two lines:

    /opt/psoft/weblogic/818sp9_80/psftaccess.log
    /opt/psoft/weblogic/818sp9_80/myserver/access.log

    inside a file and use tar with the --exclude-from=file option, these wioll not be tarred.

    my question is: if the files will be tar'd where will the tar file be located?
    Where you tell it to:

    $ tar cf /data/backup/todays_backup.tar *
    todays_backup.tar is placed in /data/backup/

    $ tar cf todays_backup.tar *
    todays_backup.tar is placed in present working directory

    See man tar for more options/explanations.

    also, can the specific date and time of the run of the script be included?
    The date command can give you just about any date format you can think of.

    $ date '+%d%m%Y'
    02122003

    Prints present day, month and year.

    Put this in a variable and use that to create the name of your tarred file.

    #!/bin/bash
    # Fill variable with current day, month and year (ddmmyyyy)
    DATESTAMP="`date '+%d%m%Y'`"
    # tar everything in current directory and put this into a file with current date attached to it and place this file in /tmp
    tar cf /tmp/todays_backup.tar.${DATESTAMP} *

    This should be enough to get you going :-)
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    4
    Rep Power
    0
    is it also possible to include in the script something that will make it run at a specific day and time?

    thanks!
  6. #4
  7. No Profile Picture
    Got source?
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2003
    Location
    Laguna Niguel, California, USA
    Posts
    2,331
    Rep Power
    14
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    4
    Rep Power
    0
    hello again, follow up question on the 1st reply:
    how do i open a tar file? its a simple file.tar that i need to open.
    thanks a lot

IMN logo majestic logo threadwatch logo seochat tools logo