- Community Home
- >
- Servers and Operating Systems
- >
- Legacy
- >
- Operating System - Tru64 Unix
- >
- Re: Usage of ECHO and grep commands
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2008 05:07 AM
10-13-2008 05:07 AM
Usage of ECHO and grep commands
set -A TELNET_HOST_ARR ${telnet_host_str}
The content present in telnet_host_str :-==========================================
alden 15.146.230.119 harpo 15.146.230.90 15.146.230.205
and target_system=alden
1>I found ipaddress by below way..Please let me know if you have any better idea.
ipaddress=$(nslookup ${target_system} |grep -p ${target_system} | grep Address | awk '{print $2}')
2>My doubt is in telnet_host_str eventhough i give ipaddress or target_system content "$? " status should be equal to zero.
echo ${telnet_host_str} || (grep $target_system && grep $ipaddress)
if [[ $? -eq 0 ]]; then
I did as above.Please let me know if you have better idea.
Thanks,
Shammer
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2008 05:14 AM
10-13-2008 05:14 AM
Re: Usage of ECHO and grep commands
Why don you use netstat -in or nslookup.
BR,
Kapil+
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2008 07:00 AM
10-13-2008 07:00 AM
Re: Usage of ECHO and grep commands
value is set by the last command in the
pipeline. In this case, that's your "awk"
command, not the "grep".
You could check for a null string ("-n" or
"-z"), instead of checking the final status.
(There are ways of extracting the status from
a command in the middle of a pipeline, but
they tend to be messy, or to use features
which are available only in fancy new shells,
like "bash".)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2008 10:55 PM
10-13-2008 10:55 PM
Re: Usage of ECHO and grep commands
ipaddress=$(nslookup ${target_system} |grep -p ${target_system} | grep Addre
ss | awk '{print $2}')
echo $ipaddress<======== here getting correct answer
echo ${telnet_host_str} || (grep $target_system && grep $ipaddress)
if [[ $? -eq 0 ]]; then
lat_server=""
if [[ ${lat_server} = "rcon" ]]
then
...........
..........
else
lat_port=""
lat_server=""
echo $ipaddress<========= here getting value=0
please let me know...
Thanks,
Shammer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2008 02:12 AM
10-14-2008 02:12 AM
Re: Usage of ECHO and grep commands
I've read your original post a couple of time now and am struggling to see what you're actually trying to do...
Could you clarify please.
Cheers
Rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2008 03:18 AM
10-14-2008 03:18 AM
Re: Usage of ECHO and grep commands
My main intention is:-
set -A TELNET_HOST_ARR ${telnet_host_str}
where {telnet_host_str} contains ipaddress as well as hostnames of machines.
Current script is checking only if you mention hostnames of machines in telnet_host_str.
Current script:-echo ${telnet_host_str} | (grep $target_system)
if [[ $? -eq 0 ]]; then
So now i am enhancing the script to check for ipaddress as well as hostnames.
So i found ipaddress as below:-
ipaddress=$(nslookup ${target_system} |grep -p ${target_system} | grep Address | awk '{print $2}')
Checking the content of telnet_host_str :-
echo ${telnet_host_str} || (grep $target_system && grep $ipaddress)
if [[ $? -eq 0 ]]; then
Hope you understood.. Please let me know if you need further information..
Please let me know if you have better way of doing it..
Thanks,
Shammer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2008 01:16 AM
10-18-2008 01:16 AM
Re: Usage of ECHO and grep commands
Personally I'd look to use Perl rather than shell scripting as you are at the moment...
It should make things much more efficient.
Cheers,
Rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2008 09:12 PM
10-19-2008 09:12 PM
Re: Usage of ECHO and grep commands
My team suggested to do this in Shell scripting .Please let me know if you have better way of doing this in shell scripting.
Also i dont have much knowledge in perl scripting.
Thanks,
Shammer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2008 05:18 AM
10-20-2008 05:18 AM
Re: Usage of ECHO and grep commands
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)
Thanks,
Shammer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2008 12:37 AM
10-21-2008 12:37 AM
Re: Usage of ECHO and grep commands
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1278970
>Now I want to grep for this ipaddress "15.146.230.119".
echo ${telnet_host_str} || (grep $target_system && grep $ipaddress)
If you want to check for BOTH being in the string you can use:
echo ${telnet_host_str} | grep $target_system | grep $ipaddress
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2008 02:21 AM
10-21-2008 02:21 AM
Re: Usage of ECHO and grep commands
I tried below way as you told,but i didnt get any output.
==========================================
set -A TELNET_HOST_ARR ${telnet_host_str}
telnet_host_str="alden porthos million athos moe moronica mullins 15.146.231.62 15.146.230.119"
target_system=groucho
ipaddress=$(nslookup ${target_system} |grep -p ${target_system} | grep Address | awk '{print $2}')
status=$(echo $telnet_host_str | grep $target_system | grep $ipaddress)
# echo $status
#
=========================================
Since i kept ipaddress value in telnet_host_str array so am expecting that ipaddress value as output in status variable.
If i keep target_system value in telnet_host_str array then i may expect that output in status variable..
So what i want is it should handle both situations apropriately..
So please help me in changing below code:-
status=$(echo $telnet_host_str | grep $target_system | grep $ipaddress)
Thanks,
Shammer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2008 02:29 AM
10-22-2008 02:29 AM
Re: Usage of ECHO and grep commands
Do you want AND or OR for the two conditions?
See your other thread for OR.
>should handle both situations appropriately.
It seems like you want OR.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2008 04:58 AM
10-22-2008 04:58 AM