• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating Platform independent scripts(Solaris and Linux)

 
Ranch Hand
Posts: 256
Netbeans IDE Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I'm not able to figure it out how i will make it UNIX platform independent.
Mainly(Solaris and Linux)
Below script runs smoothly in Linux but in Solaris its showing lots of syntax errors like its not able to reco. if statements even.
What i need to do so that the syntax will be platform independent



Can someone help me in getting this script working in both machines Linux and solaris.


Thanks.
 
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this written for Bash or another shell? It looks very much like the former to me, so wouldn't it be better off with a shebang similar to (obviously depending on the actual paths on your system):rather than just /bin/sh? It may be that Solaris is using a different shell (either Bourne itself, or another one symlinked to /bin/sh) than your Linux install. That'd explain the syntax errors since different shells have different scripting languages. Check to see what the actual shells linked to /bin/sh are on each system.
[ October 03, 2008: Message edited by: Charles Lyons ]
 
Ramakanta Sahoo
Ranch Hand
Posts: 256
Netbeans IDE Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

You are right.
Though I've limited access to My solaris machine which is at remote location.
I just did a smoke test and found that after changing to bash it not giving any syntax errors minimum.I think its ok now.
Once I will get full test on Solaris I'll let you know.
Thanks a lot for suggestions.

Ricky
 
Ramakanta Sahoo
Ranch Hand
Posts: 256
Netbeans IDE Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I back again.
I ran this script..and it ran well without syntax errors
but am facing a new problem.
I designed it to take input from command line like
./install.sh wsadmin wspassword express
where $1 will be wsadmin and $2 will be wspassword and $3 will be express
but i think its not able to compare it.
what ever i put in command line its directly taking me to last else statement.
I thought it will work like if no username and password is mentioned then it will go to last else stament..but here whether i put any argument with or not its directly taking me to last else statement.
Help me am not able to figure it out how it will able to check if there is any argument passed or not if passed then go to appropriate if stmt or elif stmt.

Thanks.
Ricky
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's hard to tell if your script above is merely missing a brace to close off the starton() function, or whether there is more code missing. I am going with the idea that your script is complete, except for that syntax error, which means that the problem is not in the passing / parsing of parameters - it appears to me to be having troubles with determining whether WebSphere is running or not.

Basically, your last if/else block is only interested in whether "${_Up}" is blank or not. And _Up is defined by whether you were able to find the case insensitive word "profile" in the list of currently running processes.

Regards, Andrew
 
Ramakanta Sahoo
Ranch Hand
Posts: 256
Netbeans IDE Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ohh sorry I forgot to mention which if else stmts
Its starton if else stmts.
and websphere is running as its able to give me the last else stmt's output. else it would have told me that WAS is not running.
As it's going to Block so its mean that websphere is running.
But in that function its not able to check all the if else stmts its directly going to stmt whether i pass any args with (./install.sh username passwd) or not. Its just acting like I have only given ./install.sh with out any arguments.
So i think there is some problem in function starton in comaparing the arguments as it going directly to the last control stmt in starton which is



Thanks.
 
Ramakanta Sahoo
Ranch Hand
Posts: 256
Netbeans IDE Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey seems I found the problem.
I added echo "1st param:$1 2nd param:$2" to check whether the command line args are available inside the starton function and ran the script as ./install.sh myID myPWD and i found that the echo stmt its showing as below:
1st param: 2nd param:
so i think all the arguments I'm passing is not available inside the starton function. Thats why its goin directly to the last else stmt in starton function as $1 and $2 all are null inside the function.
I have also checked the params outside the function and its showing all the params as 1st param:myID 2nd param:myPWD

So if anyone know how to avail all the parameters inside the starton function also.

Do I need to assign the arguments passed to some variable to make it available through out the script, something like
param1=$1
param2=$2
param3=$3

and if stmts inside starton function will be like


Correct me if I'm wrong.

Thanks.
Ricky
 
Ramakanta Sahoo
Ranch Hand
Posts: 256
Netbeans IDE Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Andrew Monkhouse

That last close brace i missed during posting my code.
Sorry for that.
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ricky Rosan:
So if anyone know how to avail all the parameters inside the starton function also.



Doh! Missed that one.

Take a look at this:

And the results when I run it:
So, basically the $x parameters within the function refer to the parameters passed to the function itself - not to the entire script.

Does that make sense?

Andrew
 
Ramakanta Sahoo
Ranch Hand
Posts: 256
Netbeans IDE Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes very true.
Its been fixed now.
I just did what i told before.I added the $1 $2 $3 with some variables.

So the problem is we need to assign it to some variable as parameters within the function refer to the parameters passed to the function itself - not to the entire script.

Now it's working absolutely fine.

Thanks,

Ricky
 
Ramakanta Sahoo
Ranch Hand
Posts: 256
Netbeans IDE Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all Ranchers,

I came back to get one more info.
This is what i want ..
bash$ export WAS_ROOT=/opt/IBM/WebSphere/AppServer/
bash$ ./install.sh
This is what i want to enable. If some one exports the WAS_ROOT value in command line then I need the exported value to be available inside script also. So that user need not vi install.sh and add the path manually.

I am nt able to figure it out how am gonna achieve this.

Thanks,
Ricky
 
Charles Lyons
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The export will make the variable available to the child script process, unless the script overrides the value locally... so you could just remove the part in the script where it sets the WAS_ROOT variable, if that is also the name of the script-local variable. Otherwise you'll need to do a test like (in Java-style pseudo-code, I'll leave you to figure out how to do it in Bash):where SCRIPT_ROOT is the variable set in the script, and WAS_ROOT is your environment variable which overrides it.

You can also override variables temporarily with env---something like:
 
Ramakanta Sahoo
Ranch Hand
Posts: 256
Netbeans IDE Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ohhh ,
Right...

Then there is no way where i can enable both .
including a option inside and outside as a export.
any way your soluion is also a good alternative also.

Thanks Charles

Cheers!!
Ricky
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you trying to have a default value that a user could override? If so, you could always check whether the value has been set within your script:


Regards, Andrew
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A good set of examples on scripts with overridable values is the /etc/init.d/scripts directory on any Red Hat-style Linux distro. In order to ease maintenance, they designed their scripts to be immutable, taking their customizations from alternative locations such as the /etc/sysconfig directory.
 
Ramakanta Sahoo
Ranch Hand
Posts: 256
Netbeans IDE Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey Andrew Thanks mate.

I used your sugg. its working...

Cheers!!

Ricky
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic