LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-19-2013, 03:20 PM   #1
imadork8317
LQ Newbie
 
Registered: Dec 2012
Posts: 5

Rep: Reputation: Disabled
Help fix my script. syntax error: unexpected end of file


This is probably simple and i probably am not doing this in the most elegant fashion, so any help would be appreciated. When i run the script it works fine but at the end i receive the follow message

"line 16: syntax error: unexpected end of file"

Here is my script

Quote:
#!/usr/bin/env bash -x
read -p "Update iOS dylib and app? " yn
case $yn in
[Yy]*) ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com upgrade_all";;
[Nn]*) ;;
esac
read -p "Update Android dylib and app? " yn
case $yn in
[Yy]* ) read -p "What is the Android dylib version? " DYLIB; ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -d ${DYLIB} -a";
read -p "Is the Android app version ${DYLIB}?" yn
case $yn in
[Yy]* ) ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -m ${DYLIB} -a";;
[Nn]* ) read -p "what is the Android app version? " APP; ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -m ${APP} -a";;
[Nn]* ) ;;
esac
 
Old 07-19-2013, 03:27 PM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
use code instead of quote for code.

anyway..

see bold comment
Code:
#!/usr/bin/env bash -x
read -p "Update iOS dylib and app? " yn
case $yn in
    [Yy]*) ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com upgrade_all";;
    [Nn]*) ;;
esac
read -p "Update Android dylib and app? " yn
case $yn in
# the below line is 'broken', should end ;; not ;
    [Yy]* ) read -p "What is the Android dylib version? " DYLIB; ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -d ${DYLIB} -a";
read -p "Is the Android app version ${DYLIB}?" yn
case $yn in
    [Yy]* ) ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -m ${DYLIB} -a";;
    [Nn]* ) read -p "what is the Android app version? " APP; ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -m ${APP} -a";;
[Nn]* ) ;;
esac
 
Old 07-19-2013, 03:31 PM   #3
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
you might be better using select/ case instead of read/ case
 
Old 07-19-2013, 03:34 PM   #4
jonesr
Member
 
Registered: Feb 2008
Location: Sacramento
Distribution: RHEL AS, mostly
Posts: 44

Rep: Reputation: 18
Think through what you are intending as the logical flow of the case statements you are starting on lines 8 and 11. Indenting your code may help. One of those case statements is never closed. The shell expects more but hits the end of the file.
 
Old 07-19-2013, 03:40 PM   #5
imadork8317
LQ Newbie
 
Registered: Dec 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Firerat View Post
use code instead of quote for code.

anyway..

see bold comment
Code:
#!/usr/bin/env bash -x
read -p "Update iOS dylib and app? " yn
case $yn in
    [Yy]*) ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com upgrade_all";;
    [Nn]*) ;;
esac
read -p "Update Android dylib and app? " yn
case $yn in
# the below line is 'broken', should end ;; not ;
    [Yy]* ) read -p "What is the Android dylib version? " DYLIB; ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -d ${DYLIB} -a";
read -p "Is the Android app version ${DYLIB}?" yn
case $yn in
    [Yy]* ) ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -m ${DYLIB} -a";;
    [Nn]* ) read -p "what is the Android app version? " APP; ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -m ${APP} -a";;
[Nn]* ) ;;
esac
If i close line 9 with ';;' then the read statement will not be included and will through a syntax error
 
Old 07-19-2013, 03:42 PM   #6
imadork8317
LQ Newbie
 
Registered: Dec 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Firerat View Post
you might be better using select/ case instead of read/ case
What is the advantage to use select vs read?
 
Old 07-19-2013, 03:52 PM   #7
imadork8317
LQ Newbie
 
Registered: Dec 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Think i fixed it. I had to close the case after esac on line 17

Code:
#!/usr/bin/env bash -x
read -p "Update iOS dylib and app? " yn
case $yn in
    [Yy]*) ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com upgrade_all";;
    [Nn]*) ;;
esac
read -p "Update Android dylib and app? " yn
case $yn in
    [Yy]* ) read -p "What is the Android dylib version? " DYLIB;
            ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -d ${DYLIB} -a";
            read -p "Is the Android app version ${DYLIB}?" yn;
                case $yn in
                    [Yy]* ) ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -m ${DYLIB} -a";;
                    [Nn]* ) read -p "what is the Android app version? " APP;
                            ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -m ${APP} -a";;
                esac;;
    [Nn]* ) ;;
esac
 
Old 07-21-2013, 09:12 AM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960
One of the more useful concepts in scripting is keeping your data separate from your code as much as possible.

One of the primary ways to do this is to pre-define all of your file paths and other fixed data strings in variables at the top of the script, rather than embedding them in the script. It keeps the clutter down and makes things cleaner and easier to debug, as well as making them easier to alter without having to go through the whole script.

Specifically, the following three strings of yours should all be pre-configured as variables:

mnadmin@contoso.com
/home/mnadmin/ops/tenant_admin/tenantcfg.rb
https://contoso.com

In addition, since the same ssh command appears over and over with only minor variations, that makes it a perfect candidate for a function. preconfigure the basic command at the top of the script, and call it with the proper options when the need arises.

Check out Scripting With Style for more tips on how to write clean and robust code.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script syntax error: unexpected end of file? smecnb Linux - Newbie 11 02-25-2013 12:44 AM
[SOLVED] Bash Script syntax error: unexpected end of file pasd Linux - Software 11 03-26-2012 07:21 PM
Bash script -----------syntax error: unexpected end of file ArthurHuang Programming 2 05-01-2009 10:29 AM
Bash script - syntax error: unexpected end of file Mr Pink Programming 7 12-19-2008 06:31 AM
Backup Script error "line 31: syntax error: unexpected end of file" eswanepoel General 7 12-07-2007 09:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration