Run a script on multiple shells?

SpruceTips

I have two servers one AIX with default shell ksh, the other RHEL with default shell bash.

I have a script that is mounted on both that will run similar commands but for either AIX or Linux. This script does not work on the bash servers, is there a way to make this script run on both bash and ksh, or would the best option be to create two different scripts?

#!/usr/bin/ksh
export OS=`uname -s`
echo "OS is "$OS"."
case $OS in
        "AIX")
                #run AIX commands;;
        "Linux")
                #run Linux commands;;
        "*")
                echo "Exiting. The OS type is not found.";;
esac
echo "Done."
exit 0

UPDATE

The commands I need to run are for user accounts on each server. An example of unlocking an account. AIX /usr/bin/chuser account_locked=false $USERNAME

Linux /usr/bin/passwd -u $USERNAME

Through further investigation I have found that the the shells location in AIX are located at /usr/bin/sh, while Redhat's are located at /bin/sh.

Can I define the shebang based on the results of "uname"?

Andrei.Tich

It would probably be easier to have two separate versions of the script. Since it is short it may not be worth adding extra code to handle the differences between the two formats as jw013 suggested. On the other hand if you had a larger script it would probably be easier to have one and make the script execute different commands depending on where it is running from.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Run "logout script" for non-login shells

From Dev

Run command in multiple active shells simultaneously

From Dev

Change shells in a script function

From Dev

Multiple shells in one window

From Dev

Define functions for multiple shells

From Dev

Run script on multiple hosts

From Dev

Run script on multiple files

From Dev

Regex compatibility across multiple shells

From Dev

sh script to run multiple files in multiple languages

From Dev

Shell command to open other shells and run commands

From Dev

Various shells won't run a binary that exists

From Dev

Why there are multiple shells in a Unix like system?

From Dev

Run a script on multiple files using numbers in their names

From Dev

run multiple instances of python script simultaneously

From Dev

Run script on multiple ec2 instances

From Dev

Avoid loading libraries on multiple run of R script

From Dev

How to run a script in python on multiple time series?

From Dev

How to run remote script on multiple host simultaneously

From Dev

How to run a script on multiple files matching a regex?

From Dev

Run multiple script files SQL with a TransactSQL

From Dev

How to run a script in multiple instances ? ( Ubuntu server )

From Dev

how to write a shell script to run multiple programs

From Dev

Google Script Run ClockTrigger Multiple Scripts

From Dev

Avoid loading libraries on multiple run of R script

From Dev

Run GNU Octave script on multiple cores

From Dev

How to run multiple config files through a script?

From Dev

A shell script to run tabix command on multiple files

From Dev

Run php script multiple times from a for loop

From Dev

Run multiple commands passed as an argument to a bash script

Related Related

HotTag

Archive