Sending output of one command to several others?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sending output of one command to several others?
# 1  
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..
# 2  
Old 04-08-2010
for ping the ip address, you can use it like this

Code:
 
for i in `nslookup yahoo.com | grep -A 20 Non | grep Address | awk '{ print $2 }'`;do ping -c 3 $i; done

# 3  
Old 04-08-2010
HA figured it out.

nslookup yahoo.com | grep -A 20 Non | grep Address | awk '{ print $2 }' | while read line; do "insertcommandhere" $line ; done

---------- Post updated at 08:29 PM ---------- Previous update was at 08:28 PM ----------

Quote:
Originally Posted by itkamaraj
for ping the ip address, you can use it like this

Code:
 
for i in `nslookup yahoo.com | grep -A 20 Non | grep Address | awk '{ print $2 }'`;do ping -c 3 $i; done

Thanks you prettymuch told me what I managed to figure out mere minutes before you posted. Thanks though.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question