Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Help/How-to - simple UNIX script / gzip (beginner)

    Hey all,

    I would like to ask your help and sorry in advance for my ignorance since I am a complete beginner in this.

    I need to create a UNIX script that will:
    - scan a small number of folders and subfolders
    - [maybe in the future store some useful data to use for populating an XML file]
    - for each final folder (each of them contain 6 files), compress the 6 files in .tgz
    [it may also need to either read a version.txt file or identify filename_v2 and use it instead of filename_v1]

    Any help or link to appropriate tutorial/link with examples would be greatly appreciated.

    Thank you very much in advance.

  2. #2
    Linux Engineer
    Join Date
    Apr 2012
    Virginia, USA
    This doesn't make a whole lot of sense. Can you be specific as to what you're trying to accomplish?

    Also, you could type of some pseudo code to describe what you want.

    if (filename_v1 exists) then
    copy name of file to x.
    write value of x to list_file.
    else ....

  3. #3
    the file tree is similar to the attachment.

    Each of the final folders (i.e. C or N in the picture) will contain some folders containing 6 different files. I want to compress them into one .tgz file.

    The .tgz file will be named according to the last version. I was thinking that this could happen either by reading a version.txt file or like the way you mention above.
    Attached Images Attached Images

  4. $spacer_open
  5. #4
    Could someone tell me what is wrong with this script?
    In one computer it says "command not found" even though I execute test scripts normally, and in another computer (with ubuntu) it says
    cd 23: can't cd to home/myname/Parent/Vol1/XXXX01

    DT=`date +%Y%m%d%H`
    for d in $SRC_DIR; do
            cd $d
            if [ -e $VERSION_FILE ]; then
                    version=`cat $VERSION_FILE`
                    if [ "$version" != "" ]; then
                            for f in `find . -path "*_v${version}"`; do
                                    dirpath=`echo $d | rev | cut -d / -f1,2 | rev | sed 's/\//-/'`
                                    cleanname=`echo $f | cut -d / -f 2 | cut -d _ -f 1`
                                    tar zcvfp $DST_DIR/PR-1-${DT}-V${version}-${dirpath}-${cleanname}.tgz $f > /dev/null 2>&1
                                    if [ $? -ne 0 ]; then
                                            echo "error in backup" # add better error handling here

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts