checking with errors

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

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.
 

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
 
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.
 

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.
 
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).
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Latest posts

Members online

Top