EvilZone
Programming and Scripting => Scripting Languages => Topic started by: neusbeer on January 13, 2012, 05:35:51 PM
-
(not sure if this is the right place to ask)
I have a small problem with pipe in linux.
case:
if have a script wich output for me a IP adres and I want to pipe it to whatweb.
script is a simple way to output ip from a domain.
so I tried
getip domain.com | whatweb
but whatweb doesn't get the IP which is given bij script 'getip'.
do I need to put a variable after whatweb
like - or "$1" or something.
Kinda stuck here,...
-
you need to read from stdin, thats what that pipe does sends the output from a command to the input of another.
ex:
$ foo() { echo "10.10.10.10"; }
$ foo
10.10.10.10
$ bar() { read IP; echo "The IP is: $IP"; }
$ bar
this is my input
The IP is: this is my input
$ foo | bar
The IP is: 10.10.10.10
if you wanted to use $1, you could do something like:
$ foo() { echo "10.10.10.10"; }
$ bar() { echo "The IP is: $1"; }
$ bar $(foo)
if you used |+$1, you could use xargs:
$ foo() { echo "10.10.10.10"; }
$ cat bar.sh
#!/bin/bash
echo "The IP is: $1"
$ foo | xargs ./bar.sh
The IP is: 10.10.10.10
although xargs won't reconize bash functions. There's a million different ways to do the same thing in bash.
-
hmm I'm not 100% getting the clue sorry..
here's the script:
getip.sh
#!/bin/bash
ping "$1" 64 1 | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | uniq
now if I type
$ getip.sh neusbeer.nl
130.12.321.100
it will result in my ip as output now I want to direct this ip to
WhatWeb (Wich identify the server,ect).
whatweb's normaly commands with
./whatweb <ip>
How can I resolve this in such I can combine various outputs from my
small bash scripts.
-
whatweb $(getip.sh neusbeer.nl)
?
-
ahh yes.. It works! thnxs..
But this don't work with multiply lines I guess?
ahh well.. got something to work with.. thankyou!
-
But this don't work with multiply lines I guess?
ahh well.. got something to work with.. thankyou!
no but this will
cat iplist.txt | while read IP; do whatweb $IP; done
cat iplist.txt | xargs -L1 whatweb
-
yes this I often use..
thnxs for the tips ;D