Operating System - Tru64 Unix
1752628 Members
5670 Online
108788 Solutions
New Discussion юеВ

Please let me know you comments on it.

 
SOLVED
Go to solution
sammer
Advisor

Please let me know you comments on it.

Hi,

Part of Current script :-
------------------------------
set -A TELNET_HOST_ARR ${telnet_host_str}
where ${telnet_host_str} contains list of hostnames.
Like telnet_host_str="alden biddy groucho"

echo ${telnet_host_str} | grep $target_system > /dev/null
where target_system="groucho"<---hostname of one machine

==============================================

Enhance script to be done is:-
---------------------------------------
set -A TELNET_HOST_ARR ${telnet_host_str}
where ${telnet_host_str} contains list of hostnames (or) ipaddress.
Like telnet_host_str="15.146.230.65 biddy 15.146.230.119"

Please have a look at my proposed solution below and let me know your valuable review comments.

Solution:
=======
ipaddress=$(nslookup ${target_system} |grep -p ${target_system} | grep Addre
ss | awk '{print $2}')
echo ${telnet_host_str} || (grep $target_system && grep $ipaddress) > /dev/n
ull


Thanks in Advance,
Shammer.
7 REPLIES 7
Rob Leadbeater
Honored Contributor

Re: Please let me know you comments on it.

Hi Shammer,

Can you please explain in words, rather than code, what you are trying to achieve...

Cheers,

Rob
sammer
Advisor

Re: Please let me know you comments on it.

Hi Rob,



I must compare "telnet_host_str"contents either with ipaddress or hostnames of machines.
Where telnet_host_str is an array which contains ipaddress or hostnames of machines.

For doing comparison i did below way:

set -A TELNET_HOST_ARR ${telnet_host_str}
ipaddress=$(nslookup ${target_system} |grep -p ${target_system} | grep Addre
ss | awk '{print $2}')
echo ${telnet_host_str} || (grep $target_system && grep $ipaddress) > /dev/n
ull

Please let me know if you have better solution.

Hope you understood..

Thanks in Advance,
Shammer.
sammer
Advisor

Re: Please let me know you comments on it.

Hi,

target_system=groucho
ipaddress="15.146.230.119"
set -A TELNET_HOST_ARR ${telnet_host_str}

Below are the list of contents present in $(telnet_host_str}:-

alden baknblak beggar biddy billion bingo bobcat bogey bradford bulldogs cos curly cyberstorm diamond dimaggi
o diverdown drooper dry ds10-1 ds10-2 ds10-3 ds10-4 hyd hel lit ber bor car nitoxy es40-1 es40-2 es40-3 es40-4 fall fleegle frigate aramis geezer gehrig getwings harp highway holein1 karloff killington larry magilla madhattr porthos million athos moe moronica mullins 15.146.231.62 ogee phantoms porcupine puddinhead reptile rhinos rinse rocks scoobydoo seawitch sine whale shemp snorky spring standish stoogeshsg sugarloaf summer tan topsail toys twldee twldum vanhal1 vanhal2 vanitya veena viola voltage wash waterville whomade winter yodel toolbox hoho humphry rose fold stooges2hsg stowe 15.146.230.119 harpo 15.146.230.90 15.146.230.205 north south east west square circle triangle rectangle oval heart crescent convex


Now I want to grep for this ipaddress "15.146.230.119".


echo ${telnet_host_str} || (grep $target_system && grep $ipaddress)

Please let me know,is that right way??

Thanks,
Shammer.
Rob Leadbeater
Honored Contributor

Re: Please let me know you comments on it.

Sorry, I still don't get what you are trying to achieve...

What output are you expecting to get ?

What are you going to do with it, once you've got it ?

If you can provide us with some background as to what the rest of the code is doing, rather than just this snippet it might help me and others to fill in the blanks.

Cheers,
Rob
sammer
Advisor

Re: Please let me know you comments on it.

Hi,

Consider that their is an array that contains 50 elements in it separated with spaces in between each element.

For displaying those array elements,i am using echo command( echo $telnet_host_str).

The output of this command is pasted in my previous update.

And assigning target_system="groucho"
Getting ipaddress of above target_system by nslookup command as below:

ipaddress=$(nslookup ${target_system} |grep -p ${target_system} | grep Address | awk '{print $2}')

Now my intention is to get the value either target_system or ipaddress by comparing with the output of "echo $telnet_host_str" in status variable as shown below:-

Please correct the below code properly..

status=$((echo $telnet_host_str | (grep $target_system || grep $ipaddress))

And obtained status variable is used by rest of the code.

Please let me know if this is not clear to you..

Thanks a lot for spending time on this..

Thanks,
Shammer.
Dennis Handly
Acclaimed Contributor
Solution

Re: Please let me know you comments on it.

>either target_system or ipaddress by comparing with the output of "echo $telnet_host_str" in status variable as shown below:
status=$((echo $telnet_host_str | (grep $target_system || grep $ipaddress))

I'm not sure why you want to use $(( )). That's for arithmetic evaluation. If you want OR you need to use:
status=$(echo $telnet_host_str | grep -e $target_system -e $ipaddress)

That looks for either $target_system OR $ipaddress or both.
Note the value of $status will be either an empty string or a copy of $telnet_host_str. If you just want it to be 0 for true, you can use:
echo $telnet_host_str | grep -q -e $target_system -e $ipaddress
status=$?
sammer
Advisor

Re: Please let me know you comments on it.

Thanks a lot Dennis..

That's the answer i needed..

Thanks,
Shammer.