| Author |
Creating Platform independent scripts(Solaris and Linux)
|
Ramakanta Sahoo
Ranch Hand
Joined: Aug 23, 2008
Posts: 235
|
|
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.
|
Regards, Ricky
Oracle Weblogic 10g Certified Expert
TechBlog
|
 |
Charles Lyons
Author
Ranch Hand
Joined: Mar 27, 2003
Posts: 836
|
|
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 ]
|
Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
|
 |
Ramakanta Sahoo
Ranch Hand
Joined: Aug 23, 2008
Posts: 235
|
|
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
Joined: Aug 23, 2008
Posts: 235
|
|
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
|
 |
Andrew Monkhouse
author and jackaroo
Marshal Commander
Joined: Mar 28, 2003
Posts: 10892
|
|
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
|
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
|
 |
Ramakanta Sahoo
Ranch Hand
Joined: Aug 23, 2008
Posts: 235
|
|
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
Joined: Aug 23, 2008
Posts: 235
|
|
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
Joined: Aug 23, 2008
Posts: 235
|
|
Hi Andrew Monkhouse That last close brace i missed during posting my code. Sorry for that.
|
 |
Andrew Monkhouse
author and jackaroo
Marshal Commander
Joined: Mar 28, 2003
Posts: 10892
|
|
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
Joined: Aug 23, 2008
Posts: 235
|
|
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
Joined: Aug 23, 2008
Posts: 235
|
|
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
Ranch Hand
Joined: Mar 27, 2003
Posts: 836
|
|
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
Joined: Aug 23, 2008
Posts: 235
|
|
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
Marshal Commander
Joined: Mar 28, 2003
Posts: 10892
|
|
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
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14568
|
|
|
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.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
Ramakanta Sahoo
Ranch Hand
Joined: Aug 23, 2008
Posts: 235
|
|
hey Andrew Thanks mate. I used your sugg. its working... Cheers!! Ricky
|
 |
 |
|
|
subject: Creating Platform independent scripts(Solaris and Linux)
|
|
|