Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Sending output of one command to several others? Post 302411528 by MrEddy on Thursday 8th of April 2010 08:51:49 PM
Old 04-08-2010
Sending output of one command to several others?

I know how I can pipe any output to another command thats easy |.

What i'm trying to do is send several addresses to the same command over and over again.

Essentially what I want to do is do an nslookup on an address and then take the resulting IP(s) and send each of those IP's to another follow on command to run for each IP that resutls from the lookup.

Thus far I can do the following to get my output to display strictly the IP's of a lookup.

nslookup yahoo.com | grep -A 20 Non | grep Address | awk '{ print $2 }'

output

69.147.125.65
72.30.2.43
98.137.149.56
209.191.122.70
67.195.160.76

So now how do I get those 5 IP's to each have another command run on them individually and give me the results of the 5 commands it runs.

So as an example how could I run this command then have the system do a ping for each IP and display the results?

If I could figure out how to do this it would save me gobs of typing because i'm always having to lookup domains and then run the test command on each of the resulting IP's for the domain. Which isn't difficult but x20 is time consuming. Would be very nice to just say. yahoo.com GO and get my answers in a second.

---------- Post updated at 07:51 PM ---------- Previous update was at 07:00 PM ----------

Well I can output the IP's to a file. Is there any way I can just run a command and tell the system to run a command for each line of data in a file?

Last edited by MrEddy; 04-08-2010 at 09:07 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sending mail from Unix - For html output

I have automated some checks - and I want to send a email when there is an issue. This is fine and I can send the email. However - I want to generate the email in html format so I can highlight any issues to a reader.. ie. If there is a disk space issue - then the email will highlight the... (2 Replies)
Discussion started by: frustrated1
2 Replies

2. UNIX for Advanced & Expert Users

sending syslog output to stderr or stdout

Is there a way to send the syslog output for a given facility to stderr or stdout? I do not want to use the "tail" command to achieve this, I would like it to go directly to stderr. Thanks in advance (1 Reply)
Discussion started by: dmirza
1 Replies

3. UNIX for Dummies Questions & Answers

Sending tar output to a remote host

Our group has recently inherited 15 servers that have not been maintained for over a year. My first action is to backup the units however there is not enough disk space on most of them to run tar. My supervisor said to look at piping the tar output to another machine, however I have been unable... (3 Replies)
Discussion started by: thumper
3 Replies

4. Shell Programming and Scripting

sending output of command via email

Hi all i want to send the output of a command by email, i have done this <comand> | mail -s <subject> <email address> which works well, but if the command retunrs noting then i just get a blank email, is there a way to stop this thanks Adam (4 Replies)
Discussion started by: ab52
4 Replies

5. UNIX for Dummies Questions & Answers

Sending awk output to nothing?

How can I direct awk output to go nowhere? I can write the data to a file easy enough or print it on the screen. But for this particular command I don't actually want the data and I don't want to create a file. I just want the data discarded. Thanks in advance (3 Replies)
Discussion started by: MrEddy
3 Replies

6. AIX

Sending script output as email

Hi i have a script which executes daily through cron. The output of the script is appended to a log file everyday It also emails me the output of the logfile as we have the mailx command in the script The below is my requirement : Normally When I get the email it sends the entire content... (3 Replies)
Discussion started by: newtoaixos
3 Replies

7. Shell Programming and Scripting

sending output to flatfile

Hi, I am writing one unix script to get row count of few tables into one sequential file my script is like this $ORACLE_HOME/bin/sqlplus -s <<EOF >output.txt userid/password@databasename set verify off set heading off set feedback off select count(*) count from tablel where ; select... (4 Replies)
Discussion started by: spmsarada
4 Replies

8. Shell Programming and Scripting

sending mail in perl.. No errors and also no output

Hi folks, I am trying to send an email in Perl script with the below code. I have written the code in Padre IDE and installed all the required modules(Mail::Sendmail) and executed the code. It is neither showing errors nor giving the output. I havnt received an mail after running the below... (1 Reply)
Discussion started by: giridhar276
1 Replies

9. Shell Programming and Scripting

Sending Sed/Echo output to Variable

I have a variable $WORDS that contains a string Then i want to use sed to break it up. echo $WORDS | sed 's// /g' I tried setting this as a variable by doing WORDS2=`echo $WORDS | sed 's// /g'` But when i do this it does not return me to the prompt properly ie. jmpprd-v1> jmpprd-v1>... (4 Replies)
Discussion started by: nitrobass24
4 Replies

10. Shell Programming and Scripting

Sending sqlplus output to a shell variable

I am trying to import a sqlplus output into a shell variable but it doesnt seem to be working. set -x export DEPENDENT_CR_NO=`sqlplus -s /nolog <<EOF conn username/passwd set heading off select dependency from custom_patches where patch_name='PATCH.zip'; exit; EOF` echo $DEPENDENT_CR_NO ... (2 Replies)
Discussion started by: beginer314
2 Replies
nslookup(1)						      General Commands Manual						       nslookup(1)

Name
       nslookup - interactively query servers running BIND, or BIND and Hesiod together

Syntax
       /usr/ucb/nslookup [ host ][ server ]
       /usr/ucb/nslookup [ - ][ server ]

Description
       The  command queries the BIND/Hesiod servers.  This command has two modes: interactive and non-interactive.  Interactive mode allows you to
       query the BIND/Hesiod server for information about various hosts and domains.  Non-interactive mode allows you to obtain just the name  and
       Internet address of a host or domain.

       Use  interactive mode if you have no arguments to provide.  In this case, queries the default BIND/Hesiod server.  To specify a BIND/Hesiod
       server to query, the first argument should be a dash (-) and the second argument should be the name of the server.

       Use non-interactive mode when the name of the host you are looking up is the first argument.  The  optional  second  argument  specifies  a
       BIND/Hesiod server.  If you do not supply a second argument, the current BIND/Hesiod server is queried.

       To terminate the command from within interactive mode, press <CTRL/D>.  To terminate only the current lookup activity, press <CTRL/C>.

Non-interactive Options
       host [server]
	    The  host option is the name of the host for which you are looking up information.	If you do not specify a server, the default server
	    is queried.  You can specify the server by either name or IP address.

       -  [server]
	    The - option returns the name and IP address of the default server, or the server you specify.  It	then  places  you  in  interactive
	    mode.  If you do not specify a server, the default server is queried.  You can specify the server by either name or IP address.

Interactive Options
       The  command  line  length must be less than 80 characters.  Any unrecognized command is interpreted as a host name.  The following are the
       standard options:

       host [server]
	    Looks up information for host using the current default server or using server if it is specified.

       server server
	    Changes the default server to the server specified.  This option uses the current default server.

       lserver server
	    Changes the default server to the server specified.  This option uses the initial default server to  look  up  information	about  the
	    server specified.

       root Changes the default server to the server for the root of the domain name space specified.  Currently, the host ns.nic.ddn.mil is used.

       finger [ name ] [ > [ > ] file ]
	    Connects with the finger server on the current host.  The current host is defined when a previous lookup for a host was successful and
	    returned address information.  See the set querytype=value command.  The name field is optional; but if  used,  it	specifies  a  user
	    name.  You can use the > and >> options to redirect output to the file specified.

       ls [ -adhlmst ] domain [ > [ > ] file ]
	    Lists the information available for the domain specified.  The default output contains host names and their Internet addresses.

	    -a	      Lists aliases of hosts in the domain, CNAME entries.

	    -d	      Lists all entries in the domain.

	    -h	      Lists CPU and operating system information for the domain, HINFO entries.

	    -l	      Same as -d.

	    -m	      Lists mail exchangers in the domain, MX entries.

	    -s	      Lists well known services in the domain, WKS entries.

	    -t	      Lists Hesiod text information, TXT entries.

	    If you redirect the output to a file, hash marks are printed for every 50 records received from the server.

       view file
	    Sorts and lists the output of the command with the command.

       help or ?
	    Print a brief summary of the commands and options.

       set keyword[=value]
	    Changes the set options that affect the lookups, except for keywords and which display information.  Valid keywords are:

	    all       Prints the current values of the options you can set, as well as information about the current default server.

	    ALL       Prints the current values of the options you can set, as well as information about the current default server.  In addition,
		      the ALL option prints the server state information.

	    [no]debug Turns on debugging mode.	Verbose information is printed about the packet sent to the server and the resulting answer.

		      The default is nodebug , which you can abbreviate to [no]deb.

	    [no]defname
		      Appends the default domain name to every lookup.	The default is nodefname, which you can abbreviate to [no]def.

	    [no]recurse
		      Tells the BIND/Hesiod server to query other servers if it does not have the information.	The default is	recurse,  and  the
		      abbreviation is [no]rec.

	    [no]vc    Uses a TCP connection when sending requests to the server.  The default is novc, and the abbreviation is [no]v.

	    domain=name
		      Changes  the default domain to the domain name specified.  The default domain name is appended to all lookup requests if the
		      defname option is set.  The default value is set in the file, which you can abbreviate to do.

	    class=value
		      Changes the class of information returned from a query to one of the following values:

		      IN	Internet (default)

		      HS	Hesiod

		      ANY	any

		      The abbreviation for the class option is cl.

	    querytype=value
		      Changes the type of information returned from a query to value.  The following is a list of the most common values:

		      A 	host Internet address (default)

		      CNAME	canonical name for an alias

		      MX	mail exchanger

		      NS	name server

		      PTR	host Internet name

		      SOA	Start of authority

		      TXT	A Hesiod data query

		      WKS	A well known service

		      The abbreviation for the querytype option is q.

	    retry=number
		      Sets the number of retries to the number specified.  If a reply to a request is not received within a certain amount of time
		      (changed with set timeout), the request is resent.  The retry value controls how many times a request is to be resent before
		      giving up.  The default retry number is and the abbreviation for the retry option is ret.

	    root=host Changes the name of the root server to the host name specified.  This affects the root command.	The  default  is  and  the
		      abbreviation is ro.

	    timeout=number
		      Changes  the time-out interval for waiting for a reply to the number specified (in seconds).  The default is 10 seconds, and
		      the abbreviation for the timeout option is t.

Tutorial
       The domain name space is tree-structured and has six top-level domains:

       o    ARPA (for ARPAnet hosts)
	    The ARPA domain is currently one of the top-level domains, but is being phased out.

       o    COM (for commercial establishments)

       o    EDU (for educational institutions)

       o    GOV (for government agencies)

       o    ORG (for not for profit organizations)

       o    MIL (for MILNET hosts)

       If you are looking for a specific host, you need to know something about the host's organization in order to determine the top-level domain
       it belongs to.  For instance, if you want to find the Internet address of a host at UCLA, do the following:

       1.   Connect with the root server, using the command.  The root server of the name space has knowledge of the top-level domains.

       2.   Connect with a server for the domain.  The domain name for UCLA, which is a university, is To connect with this server, you can type:
	    # nslookup
	    >  server ucla.edu
	    The  response  is  the names of the hosts that act as servers for the domain Note that the root server does not have information about
	    but knows the names and addresses of hosts that do.  All future queries are sent to the UCLA BIND server.

       3.   Request information about a particular host in the domain, for example, To do this, type the host name.  To request a list of hosts in
	    the UCLA domain, use the command.  The command requires a domain name (in this case, as an argument.

       Note  that  if  you  are connected with a BIND server that handles more than one domain, all lookups for host names must be fully specified
       with its domain.  For instance, the domain is served by which also services the and domains.  A lookup request for the host in  the  domain
       must  be  specified  as	However,  you  can  use the set domain=name and set defname commands to automatically append a domain name to each
       request.

       After a successful lookup of a host, use the command to see who is on the system or to get information about  a specific  person.   To  get
       other  information  about  the  host,  use the set querytype=value command, which allows you to change the type of information obtained and
       request another lookup.	The command requires that the information requested information be of type A, a host Internet address.

Hesiod Tutorial
       If you  have set up Hesiod on your ULTRIX system and would like to look at this information, you must use the and commands, where value	is
       HS and TXT respectively.

       The  following  example	presumes  that the database is set up to be distributed with BIND/Hesiod.  The answer received from the command is
       that 128.45 is the network number for the network named in the networks.dec.com domain.
       # nslookup
       Default Server:	localhost.dec.com
       Address:  127.0.0.1

       > set cl=hs
       > set q=txt
       > ethernet.networks
       Server:	localhost.dec.com
       Address:  127.0.0.1

       ethernet.networks.dec.com  ethernet:128.45
       >

Diagnostics
       If the lookup request was not successful, the command displays one of the following error messages:

       Time-out
       The server did not respond to a request after a certain amount of time (changed with set timeout=value) and a  certain  number  of  retries
       (changed with set retry=value).

       No information
       Depending  on  the  query  type	set with the set querytype command, no information about the host was available, although the host name is
       valid.

       Non-existent domain
       The host or domain name does not exist.

       Connection refused
       The connection to the BIND/Hesiod server was refused.

       Network is unreachable
       The connection to the BIND/Hesiod server cannot be made at the current time.

       Server failure
       The BIND/Hesiod server found an internal inconsistency in its database and could not return a valid answer.

       Refused
       The BIND/Hesiod server refused to service the request.

       Format error
       The name server found that the request packet was not in the proper format.  Contact your DIGITAL Field Service representative.

Files
       BIND server data file directory

       BIND server boot file

       BIND primary server hosts file

       BIND primary server reverse address hosts file

       BIND server local host reverse address host file

       BIND server cache file

       BIND data file

See Also
       finger(1), more(1), nsquery(1), resolver(3), resolver(5), named(8)
       Guide to the BIND/Hesiod Service

																       nslookup(1)
All times are GMT -4. The time now is 04:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy