0

I am using this script to check a list of ips I own to see if they are on the spam block list.

auto.sh:

while read ip ; do
    ./blacklist.sh $ip
done < block.txt

blacklist.sh is the above linked script. block.txt lists each of my ips one line at a time (I have several /22).

A typical output of a blocked ip scan looks like this:

Warning: PTR lookup failed
b.barracudacentral.org : 127.0.0.2
bb.barracudacentral.org : 127.0.0.2
black.junkemailfilter.com : 127.0.0.2
cbl.abuseat.org : 127.0.0.2
cidr.bl.mcafee.com : 127.0.0.4
dnsbl.justspam.org : 127.0.0.2
hostkarma.junkemailfilter.com : 127.0.0.2

----------------------------------------------------------
Results for <my ip>

Tested:        117
Passed:        110
Invalid:       0
Blacklisted:   7
----------------------------------------------------------

what I want to do is have the script spit out output to a file when the text above doesn't say "Blacklisted: 0".

I am not sure how to approach this, will this work?

sudo ./auto.sh "conditions where Blacklisted: is > 0" >> 12.txt

Thanks for any help

1 Answer 1

1

Put the output in a temporary file and then check its content:

./auto.sh > 12_temp.txt
grep -q 'Blacklisted:[ \t]*0$' 12_temp.txt || cat 12_temp.txt >> 12.txt
rm -f 12_temp.txt
Sign up to request clarification or add additional context in comments.

4 Comments

You need to store the result somewhere, so you can check its output. Instead of a temp file, you could also use a shell variable - it is only more complicated.
Thanks does almost exactly what I wanted. only I had to add double pipe before rm -r. like this: ./auto.sh > 12_temp.txt grep -q 'Blacklisted:[ \t]*0$' 12_temp.txt || cat 12_temp.txt >> 12.txt || rm -f 12_temp.txt. Other wise i was getting 'cat: invalid option -- 'f' Try 'cat --help' for more information.' error and 12.txt file was empty.
Unfortunately there is a formatting issue with this when opening as a text file. when I 'cat 12.txt' exactly like the above example in the my question but when I open it on a text editor, it looks like this gist.githubusercontent.com/pavs/83ea142c8cfecd882f9c/raw/… I think it might be due to how the formatting is handled in the original script: github.com/IntellexApps/blcheck/blob/master/blcheck#L458 Anything I can do to fix the output when opening the file in php?
Found the solution -p gives formatting in plain text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.