PDA

View Full Version : feeding a script with input from another script


jond
2005-05-05, 12:04 PM CDT
I have 2 scripts. I want one scripts output to feed the other script with input.

I'm trying to do it like this with script2 using a $1 variable but its
not working:
script1.sh | script2.sh

The first script just outputs a continous stream of IP addresses. The second script should check each ip address to see if it exists in a text file, and if not, add it to the text file.

Any ideas?


This is script1:
ngrep -q host 10.10.10.3 | sed -e 's ^T '| cut -d: -f1

This is script2:
grep "$1" /tmp/list.txt
if [ "$?" = "1" ]; then
echo $1 >> /tmp/list.txt
echo "$1 is new"
fi

bitrain
2005-05-05, 12:27 PM CDT
You can give it as an addition on the commandline, for example./script2 127.0.0.1 127.0.0.2 127.0.0.3In scipt2 you can then check on the number of arguments, I'm sorry, I don't know how to do that in the shell, only know c/c++