The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
If statement (yes or no) bobo UNIX for Dummies Questions & Answers 7 10-21-2008 02:46 PM
If statement - How to write a null statement april Shell Programming and Scripting 3 04-16-2008 01:14 PM
What does this statement mean? Legend986 High Level Programming 1 11-17-2007 02:48 AM
if Statement... cengiz Shell Programming and Scripting 6 07-13-2005 06:55 AM
Another question on awk - Begin statement eff_cee Shell Programming and Scripting 5 03-10-2005 01:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-02-2007
hcclnoodles hcclnoodles is offline
Registered User
  
 

Join Date: Mar 2002
Posts: 267
IF statement question

Hi there

We have boxes named server-sybase2, server-oracle1, etc etc

Does any body know how I can construct an if statement to say, if the hostname of the box contains the string "sybase" then do X ie


Code:
if [ `hostname` contains the string "sybase"]
then

X
fi
any help would be greatly appreciated
  #2 (permalink)  
Old 02-02-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
if [ `hostname` = "sybase"]
then
X
fi
  #3 (permalink)  
Old 02-02-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,100
With ksh:
if [[ $(hostname) = *sybase* ]] ; then
  #4 (permalink)  
Old 02-02-2007
hcclnoodles hcclnoodles is offline
Registered User
  
 

Join Date: Mar 2002
Posts: 267
Thanks, but the hostname will contain the word sybase ie

server-sybase16
host-sybase34
server-sybase23


etc
etc

the only one common factor is that it will contain the string sybase

cheers
  #5 (permalink)  
Old 02-02-2007
hcclnoodles hcclnoodles is offline
Registered User
  
 

Join Date: Mar 2002
Posts: 267
Thanks perderabo ...my reply got posted after your response

Is there a bourne soulution as i will be using this in a Solaris init script

Cheers
  #6 (permalink)  
Old 02-02-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,100
Code:
case `hostname` in 
        *sybase*) ans="yes" ;;
        *) ans="no" ;;
esac
if [ $ans = "yes" ]
  #7 (permalink)  
Old 02-02-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
if [ `hostname | grep sybase > /dev/null 2>&1; echo $?` -eq 0 ]
then
do_sybase_stuff
fi

f [ `hostname | grep oracle > /dev/null 2>&1; echo $?` -eq 0 ]
then
do_oracle_stuff
fi

f [ `hostname | egrep "oracle|sybase" > /dev/null 2>&1; echo $?` -eq 0 ]
then
do_ommon_oracle-sybase_stuff
fi
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 05:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0