trying to find match from multiple string if statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting trying to find match from multiple string if statement
# 1  
Old 07-20-2011
trying to find match from multiple string if statement

I'm trying to create what (should be) a simple bash script that will pull computer name and use that info to bind to one of three servers. Is there any way to do this without having a text file with the names of the servers and associated computer names?
# 2  
Old 07-20-2011
Could you provide more detail, where do you hope to pull the server name from? reverse DNS look-up (if you have the IP), use nmap to map the network and see what's attached to a given machine? randomly generate hostanmes until we hit a node that responds with some specific telltale?

Without some context the question is difficult to answer
# 3  
Old 07-20-2011
the server will be chosen based on the physical location of computer in our network which is indicated in ComputerName. ex= xyz-location all xyz computers would be bound to certain replica. This is my feeble attempt so far.


#!/bin/sh

COMPUTERNAME=`scutil --get ComputerName`

if [[ $COMPUTERNAME = *abc* ]]; then
echo "works"

fi

this part works, but I need to add more variables in the list than just abc
# 4  
Old 07-20-2011
Code:
case "$COMPUTERNAME" in
   "") echo "empty ???" ;;
   *abc*|*xyz*) echo "ok" ;;
   [0-9][A-C].txt) echo ok ;;
   [Aa][0-9]*.jpg) echo ok ;;
   *) echo not so ok ;;
esac

This User Gave Thanks to kshji For This Post:
# 5  
Old 07-20-2011
Code:
echo $COMPUTERNAME | egrep '(abc|def|xyz)' >/dev/null && echo "This works to"

This User Gave Thanks to Skrynesaver For This Post:
# 6  
Old 07-20-2011
It works! Thanks I really appreciate it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find multiple strings and replace single string

Hi, following Perl code i used for finding multiple strings and replace with single string. code: #!/usr/bin/perl my @files = <*.txt>; foreach $fileName (@files) { print "$fileName\n"; my $searchStr = ',rdata\)' | ',,rdata\)' | ', ,rdata\)'; my $replaceStr =... (2 Replies)
Discussion started by: chettyravi
2 Replies

2. UNIX for Dummies Questions & Answers

Multiple Find Conditions in IF Statement - UNIX

When I try the below if Condition with single condition its working fine. But when I try to Club both its working . But giving wrong results. In my case cond1 = -f ${filename1} = true cond2 = -f ${filename2} = true But Cond1 & Cond2 is resulting in False ??? Please advise ... (5 Replies)
Discussion started by: Shiny_Reddy
5 Replies

3. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

4. Shell Programming and Scripting

Find multiple string in one file using find command

Hi, I want find multiple string in one file using find coomand. And keeping it in one variable.grep is not working. (5 Replies)
Discussion started by: vivek1489
5 Replies

5. UNIX for Dummies Questions & Answers

How to run multiple piped commands in a find -exec statement?

I can't get this to work. Running a single command works fine: find . -name "*.dat" -exec wc -l '{}' \; gives me the file name and number of lines in each .dat file in the directory. But what if I want to pipe commands, e.g. to grep something and get the number of lines with that pattern... (3 Replies)
Discussion started by: DJR
3 Replies

6. UNIX for Dummies Questions & Answers

Find string multiple times, same line

Hi everybody, Fairly simple question here: I need an awk, sed, or grep command that will find the same string multiple times on one line needs to return all lines which contain .02 twice. I do know the exact number of characters in between the two occurrences of .02 if that helps, all... (7 Replies)
Discussion started by: jgrosecl
7 Replies

7. Shell Programming and Scripting

How to find particular string in multiple files

Hello friends, I have find a paticular string from the files present in my user for example: a username and password is hardcoded in multiple files which present in the my user.so I have to search about username in which files it is available.there are several dirctories are there,so... (5 Replies)
Discussion started by: sivaranga001
5 Replies

8. Shell Programming and Scripting

How to find particular string in multiple files with in the current directory.

Hello friends, Plz suggest the find command, How to search a string in a paticular string in miltiple files with current dirctory.:) Thanks in advance. Siva Ranganath Ch (2 Replies)
Discussion started by: sivaranga001
2 Replies

9. Shell Programming and Scripting

find string from multiple dir and redirect to new files

Hi, I am new to script and I want find one string from multiple files in diff directories and put that out put to new file. Like I have A,B & C directories and each has multiple files but one file is unic in all the directories like COMM.txt Now I want write script to find the string... (8 Replies)
Discussion started by: Mahessh123
8 Replies

10. UNIX for Dummies Questions & Answers

Find and replace a string in multiple files

I used the following script cd pathname for y in `ls *`; do sed "s/ABCD/DCBA/g" $y > temp; mv temp $y; done and it worked fine for finding and replacing strings with names etc. in all files of the given path. I'm trying to replace a string which consists of path (location of file) ... (2 Replies)
Discussion started by: pharos467
2 Replies
Login or Register to Ask a Question