Porting script from Solaris to Linux


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Porting script from Solaris to Linux
# 1  
Old 04-21-2014
Porting script from Solaris to Linux

I have a script which has commands that are located in different paths on my Linux o/s than on Solaris. For example, to make uname work, I need to do it this way in Solaris:

Code:
my $host= `/usr/bin/uname -n`

But in Linux it is:

Code:
my $host = `/bin/uname -n`

I have this issue with at least 5 commands. I have never needed to port scripts between the different operating systems, and am sure I could do something with the path statements to fix this. I don't want to create a separate script for Linux and one for Solaris. Gurus, any ideas how to make the script run on both o/s?
# 2  
Old 04-21-2014
Hi,

For most of the commands you should just be able to use something like

Code:
my $host =`uname -n`

As they will probably be OS commands, or alternatively use something loke.

Code:
if [ ${OTYP} = "AIX" ]
        then
        FLAV="df -kP"
        LOGDIR=/var/log
        else
        FLAV="df -k"
        LOGDIR=/var/log
fi

Regards

gull04
# 3  
Old 04-21-2014
Just use the PATH.

Code:
#! /usr/bin/perl

$ENV{'PATH'} = '/bin:/usr/bin';
my $host = `uname -n`;
printf "host = %s \n", $host ;

These 2 Users Gave Thanks to Perderabo For This Post:
# 4  
Old 04-21-2014
These two hints were great; and they eliminated almost all the errors. I only have one left. How about if I have to run a tar -cz command but Solaris uses gnutar and Linux uses plain tar for the z option? I assume I could do something like this:

Code:
var=`uname -a |grep -i sun |awk '{print $1}'`;if [[ $var = SunOS ]]; then `/usr/local/bin/gnutar czf; else tar cfz /local/mnt/servercs.$server.tar.gz class config;fi

but it throws errors and I'm not sure how to make this work as I have very little perl knowledge.

Last edited by newbie2010; 04-21-2014 at 02:01 PM..
# 5  
Old 04-21-2014
If you pipe from gunzip or to gzip instead of using the tar z option then it works with any tar.
# 6  
Old 04-21-2014
Any Perl persons out there? if /then type statement

Actually, I was hoping to learn something more about perl, but thanks for the replies so far, they are great. This is what I have now:

Code:
$var = `uname -a |grep -i sun |awk '{print $1}'`;$status = ($var = "SunOS")? `/usr/local/bin/gnutar czf /local/mnt/backups/nbu_db_classes.$server.$timestamp.tar.gz class config` : `ls`;

The command works great if it is sunos, but if not, it won't print the ls of the directory. Not sure how these if/then /else statements work with commands? the `ls' command is just a test to see if the statement works, it could be another command, not just 'ls`

I want it to run one command if SunOS, another if Linux (which would be anything other than SunOS). In this case, it will only run the command if it is on SunOS box, it won't run the ls command if it is on Linux o/s
# 7  
Old 04-21-2014
One portable command:
Code:
$status = `tar cf - class config | gzip >/local/mnt/backups/nbu_db_classes.$server.$timestamp.tar.gz`;


Last edited by MadeInGermany; 04-21-2014 at 05:27 PM..
This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Porting graphical Solaris application to Linux

I don't expect any quick answers, but if people have links to resources I can investigate I'd be extremely appreciative. Here is what we have today: The "application" is a multi-process train control system that uses the Unix desktop, currently CDE, several motif-based applications and sound,... (8 Replies)
Discussion started by: paz9
8 Replies

2. Shell Programming and Scripting

Porting from Solaris to Linux

Can any one please help the use of "cu command in Solaris" and as well as in Linux :confused: (1 Reply)
Discussion started by: sabee.prakash
1 Replies

3. Solaris

Porting a Linux Driver to Solaris

Hi all, Has anyone experience with proting a Linux driver (C-code) to Solaris 10? I have a Sunix SATA card with a inicio1622 chipset, but no driver available. From the website of inicio I downloaded the drivercode for Linux 2.4. Having done some investigation I found a Solaris driver... (4 Replies)
Discussion started by: longwave
4 Replies

4. Linux

when porting from HP-UX to Linux

helo, i m porting HP-UX socket application to Linux SSL-socket application. I have use htonl() in HP-UX. so when i use it in Linux, data transf is not done and application become soem time crashed. now when i remove htonl() in linux, then i got data but it will not proper order or some data may... (1 Reply)
Discussion started by: amitpansuria
1 Replies

5. Shell Programming and Scripting

porting shell script from Linux to AIX.

Hi, I am porting one shell script from Linux to AIX. I had .ksh file and i have changed it to .sh file for aix. on linux this script is running fine but on aix it gives me "unexpected end of file" error. Could any one suggest me what to do to port this script error free? Thanks in... (6 Replies)
Discussion started by: joy_1
6 Replies

6. AIX

pgrep substitute for porting a linux script to AIX 5.x

Hi, I'm trying to get this script to work on an AIX 5.3 box, I couldn't get pgrep for AIX, I also realize that ps works differently on the IBM boxes. Could anybody just give me the specifics of a work around for my problem, I'll adjust the whole script: #!/bin/bash # applabs.com #to do: #... (3 Replies)
Discussion started by: thebytegrill
3 Replies

7. Programming

porting solaris to BSD

Hi i have a C program that i need to port from solaris to BSD The flags i pass on CC in solaris are -lsocket -lnsl I use sockets and threads anyone know flags for BSD (1 Reply)
Discussion started by: yngwie
1 Replies

8. UNIX for Dummies Questions & Answers

HP-UX to linux porting

Hi all, i wanted to port some HP-UX code to linux. can anybody point to some documents or resources that would help me in doing the porting.. thanks in advance Arun Prakash (0 Replies)
Discussion started by: arunprakash
0 Replies

9. Programming

Porting to solaris

I have ported a c program to solaris. When I run , it gives me segmentation fault error at line :- memcpy ((char *)a_string ,(char *)0, MAX_READ ) ; originally this was in reliant unix as :- memcpy ( a_string , 0 , MAX_READ ) ; Can somebody help me about this ? (1 Reply)
Discussion started by: suds19
1 Replies
Login or Register to Ask a Question