Please let me know you comments on it. (976 Views)
Reply
Advisor
sammer
Posts: 24
Registered: ‎10-12-2008
Message 1 of 8 (976 Views)
Accepted Solution

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.
Honored Contributor
Rob Leadbeater
Posts: 3,582
Registered: ‎08-14-2002
Message 2 of 8 (976 Views)

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
Advisor
sammer
Posts: 24
Registered: ‎10-12-2008
Message 3 of 8 (976 Views)

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.
Advisor
sammer
Posts: 24
Registered: ‎10-12-2008
Message 4 of 8 (976 Views)

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.
Honored Contributor
Rob Leadbeater
Posts: 3,582
Registered: ‎08-14-2002
Message 5 of 8 (976 Views)

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
Advisor
sammer
Posts: 24
Registered: ‎10-12-2008
Message 6 of 8 (976 Views)

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.
Acclaimed Contributor
Dennis Handly
Posts: 25,291
Registered: ‎03-06-2006
Message 7 of 8 (976 Views)

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=$?
Advisor
sammer
Posts: 24
Registered: ‎10-12-2008
Message 8 of 8 (976 Views)

Re: Please let me know you comments on it.

Thanks a lot Dennis..

That's the answer i needed..

Thanks,
Shammer.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.