Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with sintax

Status
Not open for further replies.

p62483t

Programmer
Jan 14, 2008
11
US
Hi,

I am new at this and I would like to get this type of sintax on my Korn script

SERVERNE = `uname -n` this is good this workrs

Then I like to do an if statement to compare the servrname to a name and depending on the I would like to give a value to a variable if it is not that server then set someting else to a variable. Something like this

IF servername = abcd1 or abcd2 then
variable1 = Skyb1
else
variable1 = Sky2
FI

please help to correct
thanks!
 
Depending on the number of servers, you may be better considering the case statement. man case for details initially.

I want to be good, is that not enough?
 
An example:

case $MONTH in
01)
export MONTH='Jan'
;;
02)
export MONTH='Feb'
;;
03)
export MONTH='Mar'
;;
04)
export MONTH='Apr'
;;
05)
export MONTH='May'
;;
06)
export MONTH='Jun'
;;
07)
export MONTH='Jul'
;;
08)
export MONTH='Aug'
;;
09)
export MONTH='Sep'
;;
10)
export MONTH='Oct'
;;
11)
export MONTH='Nov'
;;
12)
export MONTH='Dec'
;;
esac

but this may be rather overblown if there are only two variables. Can you elaborate on your requirement. For example, do you wish to assign sky1 to variable1 if servername = abcd1 only, and if not abcd1 (ie abcd2), assign sky2 to variable1? In that case your if, then might be easier/better.

I want to be good, is that not enough?
 
Thank you!@ you write i want to assign sky1 to variable1 if servername = abcd1 or abcd2 only. If it is any other server i want to assign sky2 to variable1
 
Untested:

if [ $SERVERNAME = abcd1 -o $SERVERNAME = abcd2 ]
then
export variable1 = "sky1"
else
export variable2 = "sky2"
fi

Hope this gives you a starting point.


I want to be good, is that not enough?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top