1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

checking with errors

Discussion in 'Linux and Unix' started by cgjoker, Sep 25, 2003.

Thread Status:
Not open for further replies.
Advertisement
  1. cgjoker

    cgjoker Thread Starter

    Joined:
    Aug 13, 2003
    Messages:
    205
    Hey there. Was hoping someone can help me with this.

    here's my code:

    DIRff=filename

    for VAR in `cat filedate.dat`;

    if $DIRff = $DIRff$VAR > /dev/null 2> /dev/null
    echo "$DIRff$VAR already exists">> /log/log.log
    exit 1;;
    fi
    done

    Id like basically to check to see if a directory with this name already exists and if so, abort and create an error in a log or something to that effect.
     
  2. cgjoker

    cgjoker Thread Starter

    Joined:
    Aug 13, 2003
    Messages:
    205
    I've tried this and I think im getting closer but its still not working...

    DIRff=filename


    for VAR in `cat filedate.dat`;

    do

    if ["$DIRff$VAR" -ne 1]
    then
    mv $DIRff $DIRff$VAR
    mkdir $DIRff
    cp ./$DIRff$VAR/*.dct ./$DIRff/.
    else
    echo "$DIRff$VAR already exists">> /mdm_work/cg_test/test_misc/testcampop1/log/log.log
    exit 1
    fi

    done
     
  3. codejockey

    codejockey

    Joined:
    Feb 11, 2002
    Messages:
    1,405
    Try this:
    Code:
    DIRff=filename
    LOGFILE=/path-to-logfile/logfile.log
    
    for VAR in `cat filedate.dat`
    do
        if [ -d "$DIRff$VAR" ]
        then
            echo "$DIRff$VAR already exists" >> $LOGFILE
            exit 1
        else
            # insert processing here
        fi
    done
    
    Note that this logic processes each entry in the filedate.dat file in sequence. If an entry halfway through the file matches a directory name, the script will abort at that point, leaving some entries processed but others unprocessed. This may or may not be what you intend, but I point it out in the interests of clarity.

    Hope this helps.
     
  4. cgjoker

    cgjoker Thread Starter

    Joined:
    Aug 13, 2003
    Messages:
    205
    i was almost there... here is where i had my code at...

    for VAR in `cat filedate.dat`;

    do
    echo "$VAR Was Found In Filedate.dat.. Making Directory"
    done

    if [ $DIRff$VAR in `ls`];
    then

    echo "$DIRff$VAR already exists">> /mdm_work/cg_test/test_misc/testcampop1/log/log.log
    exit 1

    else
    mv $DIRff $DIRff$VAR
    mkdir $DIRff
    cp ./$DIRff$VAR/*.dct ./$DIRff/.
    fi

    I knew the ls thing wouldn't work...

    thanks for the help.
     
  5. codejockey

    codejockey

    Joined:
    Feb 11, 2002
    Messages:
    1,405
    You're more than welcome for any help I provided. You were definitely on the right track (and there are certainly other ways to do it besides what I suggested).
     
  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/167407

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice