extract part of hostname in a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extract part of hostname in a script
# 1  
Old 11-23-2011
extract part of hostname in a script

I need to automate something as part of post processing in a script . Each project is identified by a 3 letter string which is part of hostname and based on hostname I need to copy a particular file to that machine from my distribution .

here are hostnames

pprdifeap01.corp.host.net (where ife is the string I need ) and if so I copy /opt/distribution/ife.cfg to /usr/local/jboss/bin

pprdyamap05.corp.host.net ....if "yam" then cp /opt/distribution/yam.cfg /usr/local/jboss/bin

I have around 10 projects or so with different strings with different config files.

thanks
# 2  
Old 11-23-2011
Code:
 
 
#!/bin/ksh
 
vip=pprdifeap01.corp.host.net
 
host=$(echo $vip | awk -F'.' '{ print $1 }')
if [ $host = 'pprdifeap01' ]
then
   echo "host=pprdifeap01"
elif [ $host = 'pprdifeap02' ]
then
   echo "host=pprdifeap02"
else
   echo "Here I am exception"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract part of $USER in script

I need to be able to say "My name is $USER' when I use echo it work, when I use printf it print more 'my last name@.........'. How can I get just the part before the @ sign. I have to use printf. using UNIX. ------ Post updated at 01:17 PM ------ I used the activation code but I still... (2 Replies)
Discussion started by: sheltie042
2 Replies

2. Shell Programming and Scripting

Substr/Instr in shell script or extract part of text

Hi, I need to extract part of a text to two variables text is "PL/SQL procedure successfully completed. ERROR ----------------------------------------------------------------- Test Error Message PLUSVAR ---------- 1" I want "Test Error Message" in one variable and "1" in another variable.... (11 Replies)
Discussion started by: vedavrath
11 Replies

3. UNIX for Advanced & Expert Users

Need help to extract part of the string

Hi, I have a string with name as 20140412-s1-Potopolive_promos_20140412. So I want to extract only Potopolive string. Could you please help me the command. O/p : Potopolive Thx in advance (5 Replies)
Discussion started by: lkeswar
5 Replies

4. Shell Programming and Scripting

How to extract hostname from file using awk?

Hi iam having file with below lines of text pun-ras-bng-mhs-01#cont bsnl.in enk-ras-bng-cse-01#cont bsnl.in how to extract the host name and store in a variable and to print output using awk command output will be HOSTNAME pun-ras-bng-mhs-01 enk-ras-bng-cse-01 Tnx in advance. (13 Replies)
Discussion started by: surender reddy
13 Replies

5. Shell Programming and Scripting

Extract part of a string

I have a file with 100s of lines of text. I want to perform an extraction of this line: Info bpzs(pid=2652) using 1000 bits I have not been able to extract it. Should I try expr match or is there another method? This line has data both in front of and in back of it. I do not have grep -o... (5 Replies)
Discussion started by: newbie2010
5 Replies

6. Shell Programming and Scripting

Help with extract particular part of data

Input file <data> <temporary>qe2qrqerq qwewqeqwrqwrq qrerwrewrwer </temporary> </data> <sample>@!@##%#</sample> <info>12345</info> <content>2313214141454</content> <data> <temporary>qe2qrqerq qrerwrewrwer </temporary> <content>123214214523</content> </data>... (5 Replies)
Discussion started by: perl_beginner
5 Replies

7. Shell Programming and Scripting

how to extract a certain part of a line

Hi friends, I want to select and use the certain part of a line. For example I have the following line home/1245/hgdf/acsdf/myhome/afolder/H2O/endfile how can I extract the part " /myhome/afolder/H2O/endfile " thanks (6 Replies)
Discussion started by: rpf
6 Replies

8. Shell Programming and Scripting

How to extract one part from whole output

Hi All, I am trying to write a small shell programming to get db2 database size info. The command I am going to use is- db2 "CALL GET_DBSIZE_INFO(?, ?, ?, -1)" and the output of above command generally is- Value of output parameters -------------------------- Parameter Name :... (4 Replies)
Discussion started by: NARESH1302
4 Replies

9. Shell Programming and Scripting

extract last part of string.

Hi, I have a string like this BUNDLE=/home/bob/flx/user.bun how to extract only the the last part ie, only user.bun (2 Replies)
Discussion started by: vprasads
2 Replies

10. UNIX for Dummies Questions & Answers

Extract a part of file name

Hi, I want to extract a part of filename and pass it as a parameter to one of the scripts. Could someone help. File name:- NLL_NAM_XXXXX.XXXXXXX_1_1.txt. Here i have to extract only XXXXX.XXXXXXX and the position will be constant. that means that i have to extract some n characters from... (6 Replies)
Discussion started by: dnat
6 Replies
Login or Register to Ask a Question