LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-19-2013, 01:52 AM   #1
paulfoel
Member
 
Registered: Mar 2011
Posts: 43

Rep: Reputation: 0
Question Converting scripts from Solaris korn shell to run on both Solaris and RHEL


First issue I can see is the header.

On Solaris, its /usr/bin/ksh, on RHEL its /bin/ksh.
I guess one way is to add symbolic line of /usr/bin/ksh on RHEL?

Then, I guess there are command differences. One idea has been to use uname to set an environment variable then enabling an IF statement to run different commands.

Any idea where I can get a list of different commands?

Also, anything else I need to think of?
 
Old 07-19-2013, 02:11 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by paulfoel View Post
First issue I can see is the header.

On Solaris, its /usr/bin/ksh, on RHEL its /bin/ksh.
I guess one way is to add symbolic line of /usr/bin/ksh on RHEL?
That should solve that specific problem. One possible problem that I can see: If /usr is mounted separately and the script runs during boot things might not work (/usr not being mounted yet).

Quote:
Then, I guess there are command differences. One idea has been to use uname to set an environment variable then enabling an IF statement to run different commands.
This might be the core of your "problem". If these are simple scripts you might decide to put both versions into one script. If the scripts are more complicated I would personally got for 2 scripts, one for RHEL and one for Solaris. This would reduce the possibility of making cross-over mistakes and would be easier to maintain (even if you have/add lots of comments).

Quote:
Any idea where I can get a list of different commands?
You can use the Rosetta Stone for Unix and do have a look at the man pages. Some commands might have the same name and general functionality, but some options might not be present on either RHEL or Solaris.

Quote:
Also, anything else I need to think of?
Maybe to obvious: Do make sure you use the same KSH on both Solaris and RHEL (there are 2 major ones: AT&T's ksh and pdksh).
 
Old 07-19-2013, 08:49 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
"#!/usr/bin/env ksh" would probably do just as well. Let the system find it for you if it can.

As long as ksh is guaranteed to be installed on all involved systems, the shell syntax probably won't need to change much, if at all. But if you can't ensure that, then you'd have to fall back to the much more limited posix shell. I'm assuming that that won't be necessary though.

As for making the commands used compatible, probably the best thing to do is write up some functions to decide between them.

Code:
current_os=$( uname )

find(){
    case $current_os in

        Linux) command /path/to/linux/find <syntax for linux> ;;

        Solaris) command /path/to/solaris/find <syntax for solaris> ;;

        *) echo "What kind of rinky-dink OS are we running here?" ; return 1 ;;

    esac
}
You may have to get fancy in some cases, to get the input arguments to the places they need to be, or to emulate commands that don't exist on one or the other OS.

You could also set the function definitions in an external file and source that into all of your scripts (or AIUI ksh also has a function loading system you might be able to use?).

Last edited by David the H.; 07-19-2013 at 08:52 AM. Reason: small addition
 
  


Reply



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
korn shell between Solaris and Linux brian00 Linux - Newbie 3 02-01-2012 11:08 PM
[SOLVED] Detecting Whitespaces in Shell Scripts (Bash,Korn etc.) metallica1973 Programming 6 10-14-2011 08:56 AM
Choosing between Solaris 10 and Solaris Express to run sun xVM hypervisor crisostomo_enrico Solaris / OpenSolaris 1 09-26-2008 01:39 PM
Using a Korn shell in rc scripts desbyleo Solaris / OpenSolaris 3 11-12-2004 05:27 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:42 PM.

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
Open Source Consulting | Domain Registration