LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   bash line 74: syntax error: unexpected end of file help? (http://www.linuxquestions.org/questions/linux-general-1/bash-line-74-syntax-error-unexpected-end-of-file-help-755052/)

andycol 09-14-2009 06:37 AM

bash line 74: syntax error: unexpected end of file help?
 
hey guys

Please can someone help me
can you see what the error is here in my script

# PPPOE SETUP

echo -e "Would you like to Setup the ADSL?: \c "
read ADSL
if [ "$ADSL?" = "yes" ];
then
echo -e "Default Route?: \c "
read Route?
if [ "Route?" = "yes" ];
then
cat > /etc/sysconfig/network-scripts/ifcfg-ppp0 << CFG
USERCTL=yes
PEERDNS=no
TYPE=xDSL
DEVICE=ppp0
BOOTPROTO=dialup
ONBOOT=yes
PIDFILE=/var/run/pppoe-adsl-0.pid
FIREWALL=NONE
PING=.
PPPOE_TIMEOUT=80
LCP_FAILURE=3
LCP_INTERVAL=20
CLAMPMSS=1412
CONNECT_POLL=6
CONNECT_TIMEOUT=0
PERSIST=no
SYNCHRONOUS=no
DEFROUTE=yes
PROVIDER=provider
ETH=eth0
DEMAND=no
USER='andrew@andrew.co.za'
CFG
cat > /etc/ppp/pap-secrets << CFG1
"andrew@andrew.co.za" "*" andrew "*"
####### redhat-config-network will overwrite this part!!! (begin) ##########
####### redhat-config-network will overwrite this part!!! (end) ############
CFG1
else
if [ "Route?" = "no" ];
then
cat > /etc/sysconfig/network-scripts/ifcfg-ppp0 << CFG2
USERCTL=yes
PEERDNS=no
TYPE=xDSL
DEVICE=ppp0
BOOTPROTO=dialup
ONBOOT=yes
PIDFILE=/var/run/pppoe-adsl-0.pid
FIREWALL=NONE
PING=.
PPPOE_TIMEOUT=80
LCP_FAILURE=3
LCP_INTERVAL=20
CLAMPMSS=1412
CONNECT_POLL=6
CONNECT_TIMEOUT=0
PERSIST=no
SYNCHRONOUS=no
DEFROUTE=no
PROVIDER=provider
ETH=eth0
DEMAND=no
USER='andrew@andrew.co.za'
CFG2
cat > /etc/ppp/pap-secrets << CFG3
"andrew@andrew.co.za" "*" andrew "*"
####### redhat-config-network will overwrite this part!!! (begin) ##########
####### redhat-config-network will overwrite this part!!! (end) ############
CFG3
fi


when i run it it goes to the first part saying
"would you like to setup the ADSL'
then i say yes and it says

./adsl: line 74: syntax error: unexpected end of file

any ideas why?

ta
andrew

druuna 09-14-2009 06:52 AM

Hi,

You seem to be missing a lot of fi statements. I see three if [......] statements and only 1 fi statement (missing 2).

You also use an if statement right after an else statement, which could be correct but I do believe you want an elif (else if) statement.

Also: Start your script with #!/bin/bash

Hope this helps.

PS: Next time you post a piece of code, put it between code tags ( [ code ] ..... [ /code ] (without the spaces)].

andycol 09-14-2009 07:00 AM

hmm my bash is not very good

can you gimme an example?

druuna 09-14-2009 07:18 AM

Hi,

An example of what?

if - then - else - fi:
Code:

#!/bin/bash
if [[ "X" == "Y" ]]
then
  do action 1
else
  do action 2
fi

Everythime you use if, there should be a closing fi statement.

This might help: Advanced Bash-Scripting Guide

Specific (if/then/else/fi): Chapter 7. Tests

druuna 09-14-2009 07:28 AM

Hi,

I'm not sure if this is what you want/need, but here's your script (shortened and somewhat re-written):
Code:

#!/bin/bash
# PPPOE SETUP

echo -e "Would you like to Setup the ADSL?: \c "
read ADSL
if [[ "$ADSL" == "yes" ]]
then
  # yes was entered for adsl
  echo -e "Default Route?: \c "
  read Route

  if [[ $Route == "yes" ]]
  then
    # yes was entered for route
    cat > ifcfg-ppp0 << CFG
USERCTL=ABC
PEERDNS=ABC
CFG
    cat > pap-secrets << CFG1
"andrew@andrew.co.za" "*" andrew "*"
####### redhat-config-network will overwrite this part!!! (end) ############
CFG1
  else
  # no was entered for route
    cat > ifcfg-ppp0 << CFG2
USERCTL=XYZ
PEERDNS=XYZ
CFG2
    cat > pap-secrets << CFG3
"andrew@andrew.co.za" "*" andrew "*"
####### redhat-config-network will overwrite this part!!! (end) ############
CFG3
  fi
  # no was eneterd for adsl
fi

Hope this clears things up a bit.

andycol 09-14-2009 08:12 AM

aah that makes sense

Thanks alot
:)


All times are GMT -5. The time now is 12:17 PM.