Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Jun 2015 01:55:16 +0200
From:      Polytropon <freebsd@edvax.de>
To:        "Lt. Commander" <listmgr@antennex.com>
Cc:        <freebsd-questions@freebsd.org>
Subject:   Re: Script question
Message-ID:  <20150615015516.b3ea7633.freebsd@edvax.de>
In-Reply-To: <BAY404-EAS148D4B304BB066F07E84004CCB90@phx.gbl>
References:  <BAY182-W89C2924F4BDF0D2BD3810DF4BB0@phx.gbl> <CA%2Bg%2BBvjNv0PBOfmnWkzE26Tgqj6qZ-VKbHXMpuB8gak69G_T2g@mail.gmail.com> <BAY404-EAS263BBC0728E6171BD47A4AECCBA0@phx.gbl> <557B8484.9060405@gmail.com> <BAY182-W64842DB24FDD6D0F3A1854CCBA0@phx.gbl> <557C6DED.9070105@gmail.com> <BAY404-EAS148D4B304BB066F07E84004CCB90@phx.gbl>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 14 Jun 2015 15:07:18 -0500, Lt. Commander wrote:
> I know it's ugly..... but places a list of the IPs in a file plus sends me a
> message with the same list.

Yes, it is ugly, but will probably work fine. :-)

Allow me a few comments:

> #!/bin/sh
> cd /var/log

Use absolute file names - you're accessing /var/log/maillog
only once.



> grep -i spam=YES maillog > spam.tmp && \

Don't write temporary files to /var/log, use /tmp instead.



> awk '{print $11}' spam.tmp | sort | uniq > spam-hi && \

You could omit the spam.tmp file and output the grep result
into awk directly, or maybe better, use awk's pattern matching.

Then you would have something like this:

grep -i "spam=YES" /var/log/maillog | awk '{print $11}' | sort | uniq |  sed -e 's/^.*=//' > /tmp/spam-ip.txt

Or if you want to omit the grep call:

awk '/spam=YES/ {print $11}' /var/log/maillog | sort | uniq | sed -e 's/^.*=//' > /tmp/spam-ip.txt

And then continue:

cat /tmp/spam-ip.txt >> /usr/samba/mail/envelope
cat /tmp/spam-ip.txt | mail -s "SPAM IPs...." us.navy@outlook.com

Finally, you can easily remove /tmp/spam-ip.txt.



The sort | uniq step is a very interesting and useful one.
Good idea! Have a look at "man sort" if sort -g fits your
needs better than the default, which I think is -n.



-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150615015516.b3ea7633.freebsd>