problem with script and syntax error message


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem with script and syntax error message
# 1  
Old 01-20-2006
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

# 2  
Old 01-20-2006
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

# 3  
Old 01-20-2006
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...
# 4  
Old 01-20-2006
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
# 5  
Old 01-20-2006
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...
# 6  
Old 01-20-2006
I liked the quote

"and have problem debugging the problems"

:P
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Syntax Error Problem

Hi Below script is throwing an error: repos=root filename=/home/admin/Desktop/authz case $repos in root) root_folder="\" do sed "/$root_folder/a $username = $access" $filename done ;; esac exit 0 Error: ./new1.sh: line 77: syntax error near unexpected token `do' (1 Reply)
Discussion started by: ankur328
1 Replies

2. Shell Programming and Scripting

IF section problem. syntax error: unexpected end of file error

Hello, I have another problem with my script. Please accept my apologies, but I am really nooby in sh scripts. I am writing it for first time. My script: returned=`tail -50 SapLogs.log | grep -i "Error"` echo $returned if ; then echo "There is no errors in the logs" fi And after... (10 Replies)
Discussion started by: jedzio
10 Replies

3. UNIX for Dummies Questions & Answers

Problem with test syntax in script

Hi guys here i'm again with more question The code below try to find an user and write everything about him if exist, so my problem appear on line of test, where the program test if the user has secondary groups related. The rest it's clear # usugrup.sh lista todas las caracteristicas de un... (3 Replies)
Discussion started by: Newer
3 Replies

4. Shell Programming and Scripting

Problem with syntax error on line 1, teletype

Hi All, I am getting below error message while executing memory utilization script. $ ./mem1.sh syntax error on line 1, teletype syntax error on line 1, teletype $ $ uname -a SunOS 5.9 XXX Generic_122300-60 sun4u sparc SUNW,Sun-Fire-V440 $ But i can execute same script in... (3 Replies)
Discussion started by: susindram
3 Replies

5. Shell Programming and Scripting

Help with awk syntax error problem asking

Input file: 703 1192 720 1162 316 380 1810 439 1969 874 Desired output file: 3 3 awk code that I tried: (1 Reply)
Discussion started by: perl_beginner
1 Replies

6. Programming

Error message: invalid types 'bool...' (array problem)

Hello everyone. I'm stuck with an error message that neither I nor any of my computer science peeps can understand. The program I wrote is meant to be a simple decimal to binary converter, but with this message it's more complicated than I thought. Here's the code: #include <iostream>... (3 Replies)
Discussion started by: qf_woodfox
3 Replies

7. Programming

Error message: invalid types 'bool...' (array problem)

Hello everyone. I'm stuck with an error message that neither I nor any of my computer science peeps can understand. The program I wrote is meant to be a simple decimal to binary converter, but with this message it's more complicated than I thought. Here's the code: #include <iostream>... (2 Replies)
Discussion started by: qf_woodfox
2 Replies

8. Shell Programming and Scripting

K script not running / syntax problem

Hi, I have following K script, that is in rc0.d directory to be run on shutdown. It's linked using the 'ln' command to init.d.Can anyone tell me as to why it's not running, or if i have incorrect syntax?I get: "test: argument expected type=uname -p + " When running it with sh -x ... (8 Replies)
Discussion started by: darrlaw
8 Replies

9. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies

10. Shell Programming and Scripting

"syntax error at line 21 :'done' unexpected." error message"

I am trying to run the script bellow but its given me "syntax error at line 20 :'done' unexpected." error message" can someone check to see if the script is ok? and correct me pls. Today is my first day with scripting. Gurus should pls help out #!/bin/ksh # Purpose: Check to see if file... (3 Replies)
Discussion started by: ibroxy
3 Replies
Login or Register to Ask a Question