The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk Shell Script error : "Syntax Error : `Split' unexpected Herry UNIX for Dummies Questions & Answers 2 03-17-2008 08:16 AM
"syntax error at line 21 :'done' unexpected." error message" ibroxy Shell Programming and Scripting 3 08-08-2007 03:45 AM
Syntax error in script KindHead Shell Programming and Scripting 2 12-12-2006 07:28 PM
syntax error in script !! uuser Shell Programming and Scripting 13 02-15-2006 11:58 AM
Syntax error in a script... rajus19 Shell Programming and Scripting 8 12-07-2005 12:20 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-20-2006
ReV ReV is offline
Registered User
 

Join Date: Jun 2005
Posts: 34
problem with script and syntax error message

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
Reply With Quote
Forum Sponsor
  #2  
Old 01-20-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
Try this :

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
Reply With Quote
  #3  
Old 01-20-2006
Registered User
 

Join Date: Dec 2005
Location: London
Posts: 222
the following command should be in either back quotes or $(..)
we can't directly assign the like this the command ouput

Code:
NO_OF_FILES=`ls /opt/bs/sf/*.gds* | wc -w | nawk '{print $1}'`
here after nawk it should be normal single quote, not back quote.. and after the closed brace }, it should be single quote and then again single back quote...

Code:
if (`ls -l $FLAGLIST | nawk `{print $5}'' != "0") then
if (`ls -l $FLAGLIST | nawk '{print $5}'` != "0")

same thing here again...

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

check full code again for this kind of errors...
Reply With Quote
  #4  
Old 01-20-2006
ReV ReV is offline
Registered User
 

Join Date: Jun 2005
Posts: 34
I have changed the script and it look like this now:

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

SF_BASAR=/opt/basar/silicon_foundry
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 basar/silicon foundry 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
#alternative: fgrep -f $FILELIST $FLAGLIST > flaglist.tmp
#alternative: grep -F $FILELIST $FLAGLIST > flaglist.tmp
mv -f flaglist.tmp $FLAGLIST

#if there is an flag in flaglist,exit
NO_OF_FILES='ls /opt/basar/silicon_foundry/*.gds* | wc -w | nawk `{print $1}`'
#alternative: FLAGLIST_CONTENTS='wc -l $FLAGLIST'
if (`ls -l $FLAGLIST | nawk '{print $5}'` != "0") then
        exit 1
else
#       if `ls $SF_BASAR/*.gds*`<>"" then
        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
There are stil errors:

syntax error at line 31 : `filesize1="ls -l $i | nawk `{print $5}`"' unexpected
Reply With Quote
  #5  
Old 01-20-2006
Registered User
 

Join Date: Dec 2005
Location: London
Posts: 222
the line should be

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


could you please check both the postings made by my self and another friend... you have used the quotes wrongly.. interchanged...

better to use the full code provided by aigles, so that you won't make any mistake...
Reply With Quote
  #6  
Old 01-20-2006
linuxpenguin's Avatar
Registered User
 

Join Date: May 2002
Location: India
Posts: 295
I liked the quote

"and have problem debugging the problems"

:P
__________________
War doesnt determine who is right, it determines who is left
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0