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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

condition test a string 1

Status
Not open for further replies.

Birbone

MIS
Dec 20, 2000
141
0
0
US
SYSTEM_NAME=`uname -n`
PRODUCTION_SYSTEMS="systemA, systemB, systemC"

How do I write a test condition that basically says, if SYSTEM_NAME is part of the PRODUCTION_SYSTEMS then exicute commands... This script will be ran on both production and development systems.

I am not set on it being a "if" condition, I am just looking for the cleanest way to do this. I do have a workaround but it is not clean.

thanks. -B :cool:
birbone@earthlink.net
 
This will work in the Korn shell...
[tt]
SYS_NAME=`uname -n`
SYSTEMS="systemA, systemB, systemC"

[[ ${SYSTEMS} = @(*${SYS_NAME}*) ]] && print "Yes!"
[/tt]
Or, if you want to execute a bunch of commands...
[tt]
SYS_NAME=`uname -n`
SYSTEMS="systemA, systemB, systemC"

if [[ ${SYSTEMS} = @(*${SYS_NAME}*) ]]
then
# Do some commands here
print "${SYS_NAME} is in the list: ${SYSTEMS}"
fi
[/tt]
Hope this helps.

 
Or use the case statement;

SYS_NAME=`uname -n`
case $SYS_NAME in systemA|systemB|systemC)
put production commands here...
;;
case *)
otherwise run these commands...
;;
esac


This is quite simplistic and easy to add new commands... ChrisCW

** Helen Waite is now in charge of all rush orders. If you are in a hurry, just go to Helen Waite.
 
Thanks SamBones, that did exactly what I needed. Sorry ChrisCW the case statement didn't work how I needed it, but I do appreciate both of you helping. Thanks again to both of you.

-B :cool:
birbone@earthlink.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top