syntax error: unexpected end of file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting syntax error: unexpected end of file
# 1  
Old 12-25-2008
syntax error: unexpected end of file

I have a script that's failing

./zzmaster.sh: line 2: syntax error: unexpected end of file

There are 4 scripts total involved. The first 'znocc0.sh' essentially curls a page then does some sed sequences...

Code:
#!/bin/sh

#GET SENTINAL INFO

curl -b z0cookie.txt -L -k -e http://4phpfreaks.freehostia.com/index.html -A "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9
.0.4) Gecko/2008102920 Firefox/3.0.4" -L "http://4phpfreaks.freehostia.com/index.html" > shell.html

#cut for brevity - I do several manual sed sequences in between
#then for the more advanced, I call it seperately..

./zrmtd0.sh &&
mv ztmp.Ps23zp2t.2-Fpps3-wmmm0dss3 shell.html

./zrmtd0o.sh &&
mv ztmp.Ps23zp2t.2-Fpps3-wmmm0dss3 shell.html

The zrmtd0 and zrmtd0o scripts just chop up table data to trim out some of the uncessary baggage. They are both the same just cutting out different table datas.


Code:
#!/bin/sh

IN=0
CT=0
OUTFILE="ztmp.Ps23zp2t.2-Fpps3-wmmm0dss3"
echo > $OUTFILE # Start with fresh file always

cat shell.html |while read LINE
do
    # If we are entering a table row the we need to reset the TD counter
    TR=`echo $LINE |grep -i '<tr'`
    if [ -n "$TR" ]
    then
        CT=0
    else
        echo "" > /dev/null
    fi

    # Check to see if the LINE is non-empty, and has an opening td tag in it.
    TD=`echo $LINE |tr -d '\n' |grep -i '<td'`
    if [ -n "$TD" ]
    then
        # We are inside a td tag.
        IN=1
    fi

    # Check to see if the LINE is non-empty and has a closing td tag in it.
    ENDTD=`echo $LINE |tr -d '\n' |grep -i '/td>'`
    if [ -n "$ENDTD" ]
    then
        # We are leaving a td tag.
        IN=0
        # Increase the TD counter by 1
        CT=`echo "$CT+1" |bc`
    fi

    if [ "$IN" -eq 1 -a "$CT" -eq 6 -a -z "$ENDTD" ]
    then
        # Use sed to remove this TD tag AND everything in between
        echo $LINE |tr -d '\n' |sed 's/.*//' >> $OUTFILE
    elif [ "$IN" -eq 0 -a "$CT" -eq 7 ]
    then
        # We may (or may not) have an opening and closing td tag in 1 line.
        TMP=`echo $LINE |tr -d '\n' |sed 's/<TD.*//'`
        echo $TMP |sed 's/.*\/TD>//' >> $OUTFILE
    else
        echo $LINE >> $OUTFILE
    fi
done

BUT HERE IS WHERE MY PROBLEM LIES.. I create a file called zzmaster.sh with this line..

Code:
sh /home/jim/www/htdocs/curl/replicate/znocc0.sh &&

and it breaks with the error

Code:
[jim ~/www/htdocs/curl/replicate]$ ./zzmaster.sh
./zzmaster.sh: line 2: syntax error: unexpected end of file
[jim ~/www/htdocs/curl/replicate]$

Why? Eventually I'd like to reference several of these and just run a cron on that one file while sleeping once or twice in between...

sh /home/jim/www/htdocs/curl/replicate/znocc0.sh &&
sh /home/jim/www/htdocs/curl/replicate/znocc1.sh &&
sleep 20
sh /home/jim/www/htdocs/curl/replicate/znocc0.sh &&
sh /home/jim/www/htdocs/curl/replicate/znocc1.sh &&
sleep 20
sh /home/jim/www/htdocs/curl/replicate/znocc0.sh &&
sh /home/jim/www/htdocs/curl/replicate/znocc1.sh &&


At first I started the script with #!/bin/sh. It complained so I took it out. So now it just complains of the last line. Now aside from the current error, since the script -technically, when I go to configure the cron it breaks... Here's the complaint cron gives me..

Code:
mydomain.net : Dec 24 23:42:06 : jim : /usr/local/etc/sudoers is not a regular file ; TTY=ttyp1 ; PWD=/home/jim/www/htdocs/curl/replicate ; USER=root ; COMMAND=root

And here's the cron..

Code:
## replicate
*       *       *       *       *       root    /home/jim/www/htdocs/curl/replicate/zzmaster.sh

When I run the command directly as root, it doesn't complain at all. In fact, the first error doesn't come up.

Code:
jim# /home/jim/www/htdocs/curl/replicate/zzmaster.sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1154  100  1154    0     0   6929      0 --:--:-- --:--:-- --:--:--     0
him#

I'm baffled right now. Could someone help please?
# 2  
Old 12-26-2008
I think this is because you have two ampersands after the script you're trying to run in the background and should only have one i.e.

Code:
sh /home/jim/www/htdocs/curl/replicate/znocc0.sh &

# 3  
Old 12-26-2008
Quote:
Originally Posted by phpfreak
I have a script that's failing


BUT HERE IS WHERE MY PROBLEM LIES.. I create a file called zzmaster.sh with this line..

Code:
sh /home/jim/www/htdocs/curl/replicate/znocc0.sh &&

and it breaks with the error

Code:
[jim ~/www/htdocs/curl/replicate]$ ./zzmaster.sh
./zzmaster.sh: line 2: syntax error: unexpected end of file
[jim ~/www/htdocs/curl/replicate]$

Why?

You have an incomplete command.

The control operator && expects another command to follow it, to be executed if the first command completes successfully, e.g.:

Code:
cd $HOME/whatever && echo Success || echo Failed

The command after the || operator is executed if a previous command failed.
Quote:
Eventually I'd like to reference several of these and just run a cron on that one file while sleeping once or twice in between...

sh /home/jim/www/htdocs/curl/replicate/znocc0.sh &&
sh /home/jim/www/htdocs/curl/replicate/znocc1.sh &&
sleep 20
sh /home/jim/www/htdocs/curl/replicate/znocc0.sh &&
sh /home/jim/www/htdocs/curl/replicate/znocc1.sh &&
sleep 20
sh /home/jim/www/htdocs/curl/replicate/znocc0.sh &&
sh /home/jim/www/htdocs/curl/replicate/znocc1.sh &&

&& does not put jobs into the background. The keyword to do that is &.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unexpected End of File Syntax Error

Hi, I am brand new to this so I apologize ahead of time for any formatting problems. I know there is a previous (closed) thread on here about this problem but I wasn't able to fix the error following the posts there so I thought I could create a new one. Here is the error I am getting: ... (3 Replies)
Discussion started by: SierraG
3 Replies

2. Shell Programming and Scripting

Syntax error `end of file' unexpected

I checked the forum and internet, tried different workaorunds but it didnt fixed the error. Please advise on the code. #!/bin/sh CWD=/home/test/Bench cd $CWD (grep "`date +%d-%b"`" File.txt) > /home/test/Bench/dateout if then echo “data” > /home/test/ Bench /test else echo "File... (16 Replies)
Discussion started by: rajjev_saini123
16 Replies

3. Shell Programming and Scripting

cygwin syntax error: unexpected end of file

Hi, I am getting error while running the script. "syntax error: unexpected end of file" if i do cat i cant see the content of the script also it is showing as cat test.sh doner /home/master/* /home/Priya/$i| while read i j The original script is paste /home/names.txt /home/ip.txt |... (6 Replies)
Discussion started by: ranjancom2000
6 Replies

4. Shell Programming and Scripting

syntax error unexpected end of file

I am new to unix, so thank u for ur patience I try to make it work (to duplicate two first columns in several files): #!/bin/bash for i in `seq 2 5` do awk `{ print $1,$1,$2,$2,$3,$4}` final_chr.${i} > input_${i} done and i get ./my_script3.sh: command substitution: line 5: syntax... (2 Replies)
Discussion started by: kush
2 Replies

5. Shell Programming and Scripting

line 15: syntax error: unexpected end of file

Hi all, I am very new to programming and even newer to this forum as well, so I apologize if this should have been in the Newbie category, but... I am currently trying to figure out Shell Scripting and am running into problems early. Not having taken any kind of programming class, I am not even... (2 Replies)
Discussion started by: ccorder22
2 Replies

6. Shell Programming and Scripting

syntax error: unexpected end of file

I will appreciate help is this matter. i am getting this error (./getwind.scr: line 41: syntax error: unexpected end of file) in the following script : ############################## #QSUB -eo -q sb -lT 1200 -s /bin/csh #Run on an HP-UX machine or norway to access ncks # lat and lon are in... (0 Replies)
Discussion started by: peeriich
0 Replies

7. Shell Programming and Scripting

syntax error: unexpected end of file

Hi, I am newbie to UNIX scripting. I am facing this error "syntax error: unexpected end of file" while executing the following script: ------ a=$1 if then sqlplus -s prospect_stg/prospect_stg@mdmpt <<END insert into bckup_marc_parameter_lookup select * from... (6 Replies)
Discussion started by: boopathyvasagam
6 Replies

8. Shell Programming and Scripting

syntax error: unexpected end of file

Hi, I have problem in constructing "IF" condition. The below code throws "tst.sh: line 10: syntax error: unexpected end of file" #!/bin/ksh test=9 echo $test if ] then echo "in" fi echo "end" exit 0 Actually, i want to check whether the variable $test is empty or null. ... (5 Replies)
Discussion started by: tinku
5 Replies

9. Shell Programming and Scripting

script syntax error: unexpected end of file

Need help. I cannot find the reason for this error: here is the script (6 Replies)
Discussion started by: Lenora2009
6 Replies

10. Shell Programming and Scripting

syntax error: unexpected end of file

Hi, I need ur help is this matter, i have th ebelow script, and i keep getting this error: syntax error: unexpected end of file affectedRow=`cat dbOutput.log | grep "1 row affected"` echo "affectedRow : $affectedRow" if ; then echo "Look to the next OMCDB" ... (10 Replies)
Discussion started by: Alaeddin
10 Replies
Login or Register to Ask a Question