The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
for loop not working - syntax error at line 6: `end of file' unexpected debojyoty Shell Programming and Scripting 3 04-13-2009 09:31 AM
Help on shell script : syntax error at line 62: `end of file' unexpected schandrakar1 Shell Programming and Scripting 7 12-12-2008 09:10 AM
syntax error: unexpected end of file Alaeddin Shell Programming and Scripting 10 10-20-2008 07:09 AM
awk Shell Script error : "Syntax Error : `Split' unexpected Herry UNIX for Dummies Questions & Answers 2 03-17-2008 11:16 AM
syntax error at line 59: `end of file' unexpected Remi SUN Solaris 4 01-16-2007 02:48 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-25-2008
phpfreak phpfreak is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 50
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 (permalink)  
Old 12-26-2008
ArthurWaik ArthurWaik is offline
Registered User
  
 

Join Date: Apr 2007
Location: England
Posts: 4
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 (permalink)  
Old 12-26-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by phpfreak View Post
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 &.
Closed Thread

Bookmarks

Tags
awk, awk trim, trim, trim awk

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0