Script question

Polytropon freebsd at
Sun Jun 14 23:55:22 UTC 2015

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

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.

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

More information about the freebsd-questions mailing list