IF statement question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting IF statement question
# 1  
Old 02-02-2007
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  
Old 02-02-2007
Code:
if [ `hostname` = "sybase"]
then
X
fi

# 3  
Old 02-02-2007
With ksh:
if [[ $(hostname) = *sybase* ]] ; then
# 4  
Old 02-02-2007
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  
Old 02-02-2007
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  
Old 02-02-2007
Code:
case `hostname` in 
        *sybase*) ans="yes" ;;
        *) ans="no" ;;
esac
if [ $ans = "yes" ]

# 7  
Old 02-02-2007
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

2. UNIX for Dummies Questions & Answers

Question using 2 variables in a "for" statement

Good Morning, I typically run a batch of commands, from the command line, to process server operating statistics. That would look like this: (these are days of the month) In this instance I am processing a directory of file for July 6th 7th etc. Those files would have names... (9 Replies)
Discussion started by: scotm
9 Replies

3. Shell Programming and Scripting

A question about if statement

Hi everybody, I'm sorry If I ask a silly question. I have a simple code like this I have the following error: Can anyone explain for me why I have this error, and how can I correct it? Thanks in advance. (12 Replies)
Discussion started by: Dark2Bright
12 Replies

4. Programming

question about how the if statement works

on C programming, on an if statement, if u have something like if A && B && C { } if A is false, will it still move on to B and check it? (1 Reply)
Discussion started by: omega666
1 Replies

5. Shell Programming and Scripting

Quick question regarding if statement

Hi, I'm trying to write an if statement that will check the USER parm against some text but I'm not quite sure how to use the or switch in the statement.. Can anyone help me out?... If someone could also let me know when to use ( or if (( $USER != "user1" || "user2" || "user3" || "user4" ))... (6 Replies)
Discussion started by: Jazmania
6 Replies

6. Shell Programming and Scripting

perl : semi complex if statement question

Hi there I am trying to write an if statement in perl that will return "SUCCESS" if either of these conditions are true a) if $changes is greater than 5 AND the $force flag is set to 1 OR b) if $changes is greater than 0 AND $changes is less than 6 #!/usr/bin/perl -w my $force =... (5 Replies)
Discussion started by: rethink
5 Replies

7. Shell Programming and Scripting

ksh "case" statement question

Hi I have the following case statement: case $larg in *_* ) a=${larg%_*}; b=${larg#*_}; ;; *^* ) a=${larg%^*}; b=${larg#*^}; ;; esac I cannot figure out what *_* and *^* stand for... Also what a=${larg%_*}; b=${larg#*_}; and a=${larg%^*}; b=${larg#*^}; ... (1 Reply)
Discussion started by: aoussenko
1 Replies

8. Shell Programming and Scripting

compound Bash if then statement question

I am writing a Bash script that will either clone a database or setup a standby database. So Parameter 2 will be the operation type. If the value is not clone or standby I want to throw an error message. I suppose I can also do a case block. So far i have been unable to get the syntax working... (1 Reply)
Discussion started by: gandolf989
1 Replies

9. Shell Programming and Scripting

If statement - How to write a null statement

In my ksh script, if the conditions of a if statement are true, then do nothing; otherwise, execute some commands. How do I write the "do nothing" statement in the following example? Example: if (( "$x"="1" && "$y"="a" && "$z"="happy" )) then do nothing else command command fi... (3 Replies)
Discussion started by: april
3 Replies

10. Shell Programming and Scripting

Another question on awk - Begin statement

Hi, I've a question on awk. In English I want to: (a) open a file, (b) search through the file for records where length of field15 > 20 characters and (c) print out some fields in the record. I've written the following and it works OK. The trouble is this will ALWAYS write out the column... (5 Replies)
Discussion started by: eff_cee
5 Replies
Login or Register to Ask a Question