Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script problem and syntax error

Status
Not open for further replies.

omoo

Programmer
May 30, 2005
87
0
0
US
Hi I have the following script and have problem debugging the problems. The function of this script is to make sure the entire file is being received (the filesize of a data is not changing after 20 seconds) and start moving the file to another directory. This script should be started every 30mins.

Code:
#!/usr/bin/ksh
. /opt/Modules/init/ksh

SF_BASAR=/opt/bs/sf
UMC_MASK=/home/umc/dropbox/test
FLAGLIST=/home/umc/dropbox/test/flaglist
FILELIST=/home/umc/dropbox/test/filelist
DIRECTORY=/home/umc/dropbox/datacentre

#store the name of files in bs/sf to filelist
ls -l $SF_BASAR | nawk '{print $9}' > $FILELIST

#compare flag in flaglist with items in $SF_BASAR
#delete flag in flaglist that are not in $SF_BASAR

egrep "$(<$FILELIST)" $FLAGLIST > flaglist.tmp
mv -f flaglist.tmp $FLAGLIST

#if there is an flag in flaglist,exit
NO_OF_FILES=ls /opt/bs/sf/*.gds* | wc -w | nawk '{print $1}'
if (`ls -l $FLAGLIST | nawk `{print $5}'' != "0") then
    exit 1
else
    if ($NO_OF FILES != "0") then
        for i in `ls $SF_BASAR/*.gds*` do
            filesize1=`ls -l $i | nawk `{print $5}''
            sleep 20
            filesize2=`ls -l $i | nawk `{print $5}''

            if $filesize1=$filesize2 then
                #move the file
                mv i $UMC_MASK
                #create flag in flaglist
                echo $i >> FLAGLIST
            fi
        done
    fi
fi

I have the following errors:

Code:
script: /opt/bs/sf/file1.gds.gdz.gpg: cannot execute
0
script[23]: syntax error at line 29 : `filesize1=`ls -l $i | nawk `{print' unexpected

 
it looks like a quote problem:

maybe
filesize1=`ls -l $i | nawk '{print $5}'`

instead of
filesize1=`ls -l $i | nawk `{print $5}''
 
There might be a couple of issues here.
Take a look at this section:

Code:
NO_OF_FILES=ls /opt/bs/sf/*.gds* | wc -w | nawk '{print $1}'
if (`ls -l $FLAGLIST | nawk `{print $5}'' != "0") then
    exit 1

The first line is missing some quotes, and the second is a bit complicated just to see if a file is empty. Try these changes:

Code:
NO_OF_FILES=`ls /opt/bs/sf/*.gds* | wc -w | nawk '{print $1}'`
if [ -s $FLAGLIST ] then
    exit 1

Also make the changes suggested by Gloups.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top