LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
LinkBack Search this Thread
Old 02-16-2010, 01:04 PM   #1
snakernetb
LQ Newbie
 
Registered: Dec 2004
Location: Bloomington, IL
Distribution: FC3
Posts: 5

Rep: Reputation: 0
syntax error near unexpected token `then'


Hi all, I am trying to build a script that runs on AIX, Solaris, and various flavors of Linux as well. It is very simple, or so I thought. I have the AIX and Solaris servers working well. Next I tried to get my workstation to run the script and it bombed. I am running Fedora 12 x86_64, but that isn't really important. I have various flavors of Linux. Some CentOS, RH, and even a Gentoo server. The script I have runs every hour on all servers. I can push out changes and install software with it, but the Linux WS won't run it. Here is my script:

uname=`uname`
os1="AIX"
os2="SunOS"
os3="Linux"
#echo $oslevel
if [[ $uname = $os1 ]] then
/tools/HourlyProcess/HourlyProcess_Kickoff_AIX
fi
if [[ $uname = $os2 ]] then
/tools/HourlyProcess/HourlyProcess_Kickoff_Sun
fi
if [[ $uname = $os3 ]] then
/tools/HourlyProcess/HourlyProcess_Kickoff_Linux
fi
exit

And here are the errors:

/tools/HourlyProcess/HourlyProcess_Kickoff: line 6: syntax error near unexpected token `then'
/tools/HourlyProcess/HourlyProcess_Kickoff: line 6: `if [[ $uname = $os1 ]] then'

Is this just an issue with going between ksh and bash?
 
Old 02-16-2010, 01:10 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,523
Blog Entries: 27

Rep: Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174
Either put a ";" after the "]]" and before the "then" or put the "then" on another line.
 
Old 02-16-2010, 01:32 PM   #3
snakernetb
LQ Newbie
 
Registered: Dec 2004
Location: Bloomington, IL
Distribution: FC3
Posts: 5

Original Poster
Rep: Reputation: 0
That got it

Thanks, in troubleshooting the Solaris portion I had to remove the #!/bin/ksh at the top of the script. I doing all of that I also removed the ; before the then as well. It is working everywhere now, I didn't even notice that was gone until you brought it up.

Last edited by snakernetb; 02-16-2010 at 01:32 PM. Reason: spelling
 
Old 02-16-2010, 06:30 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,093

Rep: Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995
You can get the real ksh on Linux these days, so I'd specify that at the top again (check the paths on each OS).
You don't want to assume that the 'default' shell will always be ksh (or whatever).
 
Old 02-16-2010, 06:40 PM   #5
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
You may not be able to know whether ksh is in /bin, /usr/bin or /usr/local/bin. For ksh scripts to run on all *nixes, they usually start:
#!/usr/bin/env ksh
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sh: syntax error near unexpected token `(' venkatesh_b Linux - Newbie 1 05-16-2009 05:44 AM
Syntax error near unexpected token fi Nortekman Linux - Newbie 8 02-27-2009 03:48 PM
syntax error near unexpected token -what does this mean? rmnature Linux - Newbie 5 02-14-2009 08:19 AM
syntax error near unexpected token Aigarzs Linux - Newbie 3 01-12-2008 03:39 PM
syntax error near unexpected token deskjockey39 Linux - General 2 01-16-2007 08:47 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration