ispCP - Board - Support
script help please - Printable Version

+- ispCP - Board - Support (http://www.isp-control.net/forum)
+-- Forum: ispCP Omega Development Area (/forum-1.html)
+--- Forum: General discussion (/forum-11.html)
+--- Thread: script help please (/thread-8436.html)



script help please - ChrisJones - 11-14-2009 04:35 AM

this is what i want to do...
generate a greylist logfile for each domain , this is what the current manual command looks like.
Code:
cat /var/log/syslog | grep domain.co.uk |postgreyreport --nosingle_line --check_sender=mx,a --show_tries --separate_by_subnet=.:===========================================================​====================================\n. >/var/www/virtual/domain.co.uk/htdocs/postgrey.log

i think a command something like this could work
Code:
cat /var/log/syslog | grep $domain |postgreyreport --nosingle_line --check_sender=mx,a --show_tries --separate_by_subnet=.:===========================================================​====================================\n. >/var/www/virtual/$domain/htdocs/postgrey.log

the output really shouldnt be in a public folder unless protected. but im not very good at scripting tbh

at the moment i currenly have a command that lists all domains.
any help would be appreciated


RE: script help please - Knut - 11-14-2009 03:53 PM

short and untested:

Code:
#!/bin/bash

FOLDER="/var/mail/virtual/"

for domain in $(ls $FOLDER); do
  if test -d /var/www/virtual/$domain/htdocs; then
    echo "Report for Domain $domain"
    cat /var/log/syslog | grep $domain |postgreyreport --nosingle_line -check_sender=mx,a --show_tries > /var/www/virtual/$domain/htdocs/postgrey.log
  fi

done

Knut


RE: script help please - ChrisJones - 11-15-2009 02:51 PM

Thanks knut

below is the final script which i called postgreylog , added a cron job to run before syslog has been cleared. Not all systems have mail logging in syslog so customise as required.

Changed where the file is saved a little , might be interesting to get something like this into the users control panel so they can check to see if real mail is being blocked (my wife had 5 email addresses today).

had to change it just a little but overall it does it's job. Thanks for helping

to run script past into your most used editor
and save , then chmod +x it.
run to test.

sample output here
Code:
#!/bin/bash
#postgreylog v1
#This script outputs the blocked mail into a readable logfile for each domain
#Idea Chris Jones 2009
#script written by Knut on isp-control.net forums 2009
#script re-edited by Chris Jones 2009

# Folder gathers the list of domains
FOLDER="/var/mail/virtual/"

#log should be the file you want read by postgrey report
log="/var/log/syslog"

#output edit the output so non-readable on net or post into a protected folder
output="/var/www/virtual/"

#Main script
#I require the .:====== part to make it readable by me it also looks better
for domain in $(ls $FOLDER); do
  if test -d /var/www/virtual/$domain/htdocs; then
    echo "Report for Domain $domain"
    cat $log | grep $domain |postgreyreport --nosingle_line --check_sender=mx,a --show_tries --separate_by_subnet=.:===================================From====================​===============TO=======================:.MailServer-Sending-Mail\ > $output$domain/postgrey.log
  fi

done

Thanks
Chris Jones


RE: script help please - Knut - 11-15-2009 03:27 PM

Hi,

you can change the line
Code:
if test -d /var/www/virtual/$domain/htdocs; then
to
Code:
if test -d $output$domain/htdocs; then

Knut


RE: script help please - ChrisJones - 11-16-2009 09:59 PM

yeah saw that not too long after , but it was early in the morning for me Smile


RE: script help please - Knut - 11-16-2009 10:02 PM

You know the usermap ? http://www.isp-control.net/forum/usermap.php :-)

Knut


RE: script help please - ChrisJones - 11-16-2009 10:37 PM

lol look at the top bubble for uk ,slightly out of place but only a little