<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://wiki.ninjafocus.net/skins/common/feed.css?116"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.ninjafocus.net/index.php?title=Special:Newpages&amp;feed=atom</id>
		<title>NinjaFocus - New pages [en]</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.ninjafocus.net/index.php?title=Special:Newpages&amp;feed=atom"/>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Special:Newpages"/>
		<updated>2012-05-20T19:53:29Z</updated>
		<subtitle>::You must have ninja focus to complete your mission::NinjaFocus::</subtitle>
		<generator>MediaWiki 1.12.1</generator>

	<entry>
		<id>http://wiki.ninjafocus.net/SSH_ID_Installer</id>
		<title>SSH ID Installer</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/SSH_ID_Installer"/>
				<updated>2012-02-19T09:57:15Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[category:linux]]&lt;br /&gt;
[[category:scripts]]&lt;br /&gt;
[[category:bash]]&lt;br /&gt;
&lt;br /&gt;
This script, when passed an ssh public id and a list of logins, will use ssh to connect to the logins provided and install the new ssh id.&lt;br /&gt;
&lt;br /&gt;
Although this script contains some basic safety checks, you would be brave to try and use it with out understanding how it works and being very certain that it will work in your environment. When I want to install a new id using a script like this, the first thing I do is open ssh connections to all the servers. Then if there is an error while the script it running, I can get in and fix it.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
key=&amp;quot;$1&amp;quot;&lt;br /&gt;
shift&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$key&amp;quot; = &amp;quot;$(echo &amp;quot;$key&amp;quot; | sed -e 's/[a-zA-Z0-9 +\/\.=@-]//g')&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo supplied key contains invalid characters&lt;br /&gt;
    exit&lt;br /&gt;
fi&lt;br /&gt;
if [ &amp;quot;$key&amp;quot; != &amp;quot;$(echo &amp;quot;$key&amp;quot; | egrep &amp;quot;^ssh-(dsa|rsa) &amp;quot;)&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo supplied key format looks bad&lt;br /&gt;
    exit&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
date=$(date +%F-%T)&lt;br /&gt;
&lt;br /&gt;
echo $date&lt;br /&gt;
echo &amp;quot;$key&amp;quot;&lt;br /&gt;
&lt;br /&gt;
for login in $@&lt;br /&gt;
do&lt;br /&gt;
    echo &amp;quot;$login&amp;quot;&lt;br /&gt;
    if [ &amp;quot;$login&amp;quot; = &amp;quot;$(echo &amp;quot;$login&amp;quot; | sed -e 's/[a-zA-Z0-9 +\/\.=@-]//g')&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        echo &amp;quot;$login Skipped: '$login' contains invalid characters&amp;quot;&lt;br /&gt;
        continue&lt;br /&gt;
    fi&lt;br /&gt;
    ssh $login &amp;quot;if [ ! -f .ssh/authorized_keys ]&lt;br /&gt;
                then&lt;br /&gt;
                    echo $login Skipped: could not find file;&lt;br /&gt;
                    exit;&lt;br /&gt;
                fi;&lt;br /&gt;
                if [ ! -O .ssh ]&lt;br /&gt;
                then&lt;br /&gt;
                    echo $login Skipped: .ssh does not exist or has incorrect permissions;&lt;br /&gt;
                    exit;&lt;br /&gt;
                fi;&lt;br /&gt;
                cp -p .ssh/authorized_keys .ssh/authorized_keys.$date;&lt;br /&gt;
                if [ ! -f .ssh/authorized_keys.$date ]&lt;br /&gt;
                then&lt;br /&gt;
                    echo $login Skipped: could not backup backup existing file;&lt;br /&gt;
                    exit;&lt;br /&gt;
                fi;&lt;br /&gt;
                if [ ! -O .ssh/authorized_keys ];&lt;br /&gt;
                then &lt;br /&gt;
                    rm -f .ssh/authorized_keys;&lt;br /&gt;
                    cp -p .ssh/authorized_keys.$date .ssh/authorized_keys;&lt;br /&gt;
                fi;&lt;br /&gt;
                echo '${key}' &amp;gt;&amp;gt; .ssh/authorized_keys;&lt;br /&gt;
    &amp;quot;&lt;br /&gt;
    echo -n &amp;quot;current ssh key on this machine for $login: &amp;quot;; ssh $login &amp;quot;echo OK&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Spam-Info.py</id>
		<title>Spam-Info.py</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Spam-Info.py"/>
				<updated>2012-02-03T17:45:02Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: New page: [[category:linux]] [[category:python]] [[category:scripts]]  Pipe in some exim main log lines, pass the email address of an abused account, get a report of how much mail they sent, how man...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[category:linux]]&lt;br /&gt;
[[category:python]]&lt;br /&gt;
[[category:scripts]]&lt;br /&gt;
&lt;br /&gt;
Pipe in some exim main log lines, pass the email address of an abused account, get a report of how much mail they sent, how many recipients it was relayed to and how spammy the mail was.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
# -*- coding: utf-8 -*-&lt;br /&gt;
&lt;br /&gt;
import os, sys, time&lt;br /&gt;
&lt;br /&gt;
fromaddr = sys.argv[1]&lt;br /&gt;
print fromaddr&lt;br /&gt;
&lt;br /&gt;
received, recipients, rejects, relayed = 0, 0, 0, 0&lt;br /&gt;
msgids = []&lt;br /&gt;
sa_scores = {}&lt;br /&gt;
&lt;br /&gt;
for line in sys.stdin:&lt;br /&gt;
    msgid = line[20:36]&lt;br /&gt;
    sa_index = line.find(&amp;quot;Spamassassin score is &amp;quot;)&lt;br /&gt;
    if (sa_index &amp;gt; -1):&lt;br /&gt;
       sa_scores[msgid] = float(line[sa_index + 22:])&lt;br /&gt;
    if (line.find(&amp;quot;rejected after DATA: Spam messages are not welcome here&amp;quot;) &amp;gt; -1 and line.find(&amp;quot;F=&amp;lt;%s&amp;gt;&amp;quot; % (fromaddr,)) &amp;gt; -1):&lt;br /&gt;
        rejects = rejects + 1&lt;br /&gt;
        sa_scores.pop(msgid)&lt;br /&gt;
        continue&lt;br /&gt;
    if (line.find(&amp;quot; &amp;lt;= &amp;quot;) &amp;gt; -1):&lt;br /&gt;
        index = line.find(&amp;quot; from &amp;lt;%s&amp;gt; &amp;quot; % (fromaddr,))&lt;br /&gt;
        if (index &amp;gt; -1):&lt;br /&gt;
            received = received + 1&lt;br /&gt;
            rcpt_i = line.find(&amp;quot; for &amp;quot;, index + len(fromaddr) + 8) + 5&lt;br /&gt;
            recipients = recipients + len(line[rcpt_i:].split())&lt;br /&gt;
            msgids.append(msgid)&lt;br /&gt;
            continue&lt;br /&gt;
    if (msgid in msgids):&lt;br /&gt;
        if (line.find(&amp;quot; =&amp;gt; &amp;quot;) &amp;gt; -1 or line.find(&amp;quot; -&amp;gt; &amp;quot;) &amp;gt; -1):&lt;br /&gt;
            relayed = relayed + 1&lt;br /&gt;
&lt;br /&gt;
sys.stdout.write(&amp;quot;Rejected %d emails\n&amp;quot; % rejects)&lt;br /&gt;
sys.stdout.write(&amp;quot;Received %d emails, for %d receipients and relayed to %d recipients\n&amp;quot; % (received, recipients, relayed))&lt;br /&gt;
&lt;br /&gt;
for msgid in sa_scores.keys():&lt;br /&gt;
    if (msgid not in msgids):&lt;br /&gt;
        sa_scores.pop(msgid)&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
    sa_scores = sa_scores.values()&lt;br /&gt;
    sa_scores.sort()&lt;br /&gt;
    sa_total = 0&lt;br /&gt;
    for sa_score in sa_scores:&lt;br /&gt;
        sa_total = sa_total + sa_score&lt;br /&gt;
    sys.stdout.write(&amp;quot;SA Scores: min %.1f, med %.1f, max %.1f\n&amp;quot; % (sa_scores[0], (sa_total / len(sa_scores)), sa_scores[-1]))&lt;br /&gt;
except:&lt;br /&gt;
    pass&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Cyrus</id>
		<title>Cyrus</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Cyrus"/>
				<updated>2011-07-16T13:42:26Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:linux]]&lt;br /&gt;
[[Category:servers]]&lt;br /&gt;
&lt;br /&gt;
Creating mailboxes and checking/setting permissions:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
$ cyradm  --user cyradm imap.example.com&lt;br /&gt;
Password: &lt;br /&gt;
imap.example.com&amp;gt; cm office.reports&lt;br /&gt;
imap.example.com&amp;gt; lam office.reports&lt;br /&gt;
bob lrswiktecda&lt;br /&gt;
bill lrswiktecda&lt;br /&gt;
babs lrswiktecda&lt;br /&gt;
anyone p&lt;br /&gt;
imap.example.com&amp;gt; sam office.reports becca lrswipd&lt;br /&gt;
imap.example.com&amp;gt; lam office.reports&lt;br /&gt;
bob lrswiktecda&lt;br /&gt;
bill lrswiktecda&lt;br /&gt;
babs lrswiktecda&lt;br /&gt;
becca lrswipd&lt;br /&gt;
anyone p&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
imtest [http://cyrusimap.web.cmu.edu/twiki/bin/view/Cyrus/ImtestByHand http://cyrusimap.web.cmu.edu/twiki/bin/view/Cyrus/ImtestByHand]&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
imtest -t &amp;quot;&amp;quot; -u bob -a cyradm imap.example.com&lt;br /&gt;
&lt;br /&gt;
-t - keyfile (blank)&lt;br /&gt;
&lt;br /&gt;
-u user for authorization (to simulate access as)&lt;br /&gt;
&lt;br /&gt;
-a user for authentication&lt;br /&gt;
&lt;br /&gt;
hostname&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;unexpunge -l user.bob&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Exim</id>
		<title>Exim</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Exim"/>
				<updated>2011-07-16T13:37:31Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:linux]]&lt;br /&gt;
[[Category:servers]]&lt;br /&gt;
&lt;br /&gt;
Various little things to do when running an exim mail server.&lt;br /&gt;
&lt;br /&gt;
queue &lt;br /&gt;
 &amp;lt;nowiki&amp;gt;$ exim -bp&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
queue summary:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;$ exim -bp|exiqsumm&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;$ exim -brp | exiqsumm | tail         &lt;br /&gt;
    1       0    2252     36m     36m  windsorhoteis.com.br&lt;br /&gt;
    1       1    1126     37h     37h  ww.com&lt;br /&gt;
    1       1    6246     26h     26h  yahoo.co.th&lt;br /&gt;
    4       0    20KB      4m      0m  yahoo.co.uk&lt;br /&gt;
    9       6    22KB     47m      0m  yahoo.com&lt;br /&gt;
    2       2    2252     39h     19m  yahoo.de&lt;br /&gt;
    1       0   110KB     87m     87m  yorku.ca&lt;br /&gt;
---------------------------------------------------------------&lt;br /&gt;
  705     309    53MB      5d      0m  TOTAL&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
check routing:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;bash-2.03$ exim -bt bob@example.com&lt;br /&gt;
bob@imap.example.com&lt;br /&gt;
    &amp;lt;-- bob@example.com&lt;br /&gt;
  router = imapmail, transport = imaptransport&lt;br /&gt;
  host imap.example.com [10.10.0.34]&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;  &lt;br /&gt;
  &lt;br /&gt;
headers&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;$ exim -Mvh 1Ni4hu-0000ri-KQ&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
body&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;$ exim -Mvb 1Ni4hu-0000ri-KQ&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Stop attempting to deliver mails that have been on the queue for 4 days or more. (Bounce messages are discarded).&lt;br /&gt;
Senders are sent an Error message &amp;quot;cancelled by administrator&amp;quot;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;exiqgrep -i -o 345600 | xargs exim -Mg&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove frozen messages:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;exiqgrep -iz | xargs exim -Mrm&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
exim -bd -q15m&lt;br /&gt;
exim -Mc &amp;lt;msg id&amp;gt; &lt;br /&gt;
&lt;br /&gt;
-d debug &lt;br /&gt;
-M &amp;lt;msg id&amp;gt;&lt;br /&gt;
-q process queue&lt;br /&gt;
-db daemon&lt;br /&gt;
-dbf don't fork off&lt;br /&gt;
-bP [setting] config dump&lt;br /&gt;
-bp [msg ids] show mail queue &lt;br /&gt;
-bpr as -bp with messages not sorted in order of arrival&lt;br /&gt;
-bpc number of messages in queue&lt;br /&gt;
&lt;br /&gt;
mailq = exim -bp &lt;br /&gt;
runq = exim -q&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Testing_Clamav</id>
		<title>Testing Clamav</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Testing_Clamav"/>
				<updated>2011-07-16T13:31:27Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: New page: [[Category:linux]] [[Category:bash]] [[Category:servers]]  From a remote machine allowed access clamd, use clamd-stream-client  with the clamav test virus files. The test virus files are b...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:linux]]&lt;br /&gt;
[[Category:bash]]&lt;br /&gt;
[[Category:servers]]&lt;br /&gt;
&lt;br /&gt;
From a remote machine allowed access clamd, use clamd-stream-client &lt;br /&gt;
with the clamav test virus files. The test virus files are built when compiling clamav &lt;br /&gt;
http://www.clamav.net/download/third-party-tools/3rdparty-misc&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;kjw-1:clamav-0.97-test-files kieranwhitbread$ for virus in clam*; do echo &amp;quot;$virus: $(clamd-stream-client -d clamd.example.com &amp;lt; $virus )&amp;quot;; done&lt;br /&gt;
clam-aspack.exe: ClamAV-Test-File&lt;br /&gt;
clam-fsg.exe: ClamAV-Test-File&lt;br /&gt;
clam-mew.exe: ClamAV-Test-File&lt;br /&gt;
clam-nsis.exe: ClamAV-Test-File&lt;br /&gt;
clam-pespin.exe: ClamAV-Test-File&lt;br /&gt;
clam-petite.exe: ClamAV-Test-File&lt;br /&gt;
clam-upack.exe: ClamAV-Test-File&lt;br /&gt;
clam-upx.exe: ClamAV-Test-File&lt;br /&gt;
clam-v2.rar: ClamAV-Test-File&lt;br /&gt;
clam-v3.rar: ClamAV-Test-File&lt;br /&gt;
clam-wwpack.exe: ClamAV-Test-File&lt;br /&gt;
clam-yc.exe: ClamAV-Test-File&lt;br /&gt;
clam.7z: ClamAV-Test-File&lt;br /&gt;
clam.arj: ClamAV-Test-File&lt;br /&gt;
clam.bin-be.cpio: ClamAV-Test-File&lt;br /&gt;
clam.bin-le.cpio: ClamAV-Test-File&lt;br /&gt;
clam.bz2.zip: ClamAV-Test-File&lt;br /&gt;
clam.cab: ClamAV-Test-File&lt;br /&gt;
clam.chm: ClamAV-Test-File&lt;br /&gt;
clam.d64.zip: ClamAV-Test-File&lt;br /&gt;
clam.ea05.exe: ClamAV-Test-File&lt;br /&gt;
clam.ea06.exe: ClamAV-Test-File&lt;br /&gt;
clam.exe: ClamAV-Test-File&lt;br /&gt;
clam.exe.binhex: ClamAV-Test-File&lt;br /&gt;
clam.exe.bz2: ClamAV-Test-File&lt;br /&gt;
clam.exe.html: ClamAV-Test-File&lt;br /&gt;
clam.exe.mbox.base64: ClamAV-Test-File&lt;br /&gt;
clam.exe.mbox.uu: ClamAV-Test-File&lt;br /&gt;
clam.exe.rtf: ClamAV-Test-File&lt;br /&gt;
clam.exe.szdd: ClamAV-Test-File&lt;br /&gt;
clam.impl.zip: ClamAV-Test-File&lt;br /&gt;
clam.mail: ClamAV-Test-File&lt;br /&gt;
clam.newc.cpio: ClamAV-Test-File&lt;br /&gt;
clam.odc.cpio: ClamAV-Test-File&lt;br /&gt;
clam.ole.doc: ClamAV-Test-File&lt;br /&gt;
clam.pdf: ClamAV-Test-File&lt;br /&gt;
clam.ppt: ClamAV-Test-File&lt;br /&gt;
clam.sis: ClamAV-Test-File&lt;br /&gt;
clam.tar.gz: ClamAV-Test-File&lt;br /&gt;
clam.tnef: ClamAV-Test-File&lt;br /&gt;
clam.zip: ClamAV-Test-File&lt;br /&gt;
clam_IScab_ext.exe: ClamAV-Test-File&lt;br /&gt;
clam_IScab_int.exe: ClamAV-Test-File&lt;br /&gt;
clam_ISmsi_ext.exe: ClamAV-Test-File&lt;br /&gt;
clam_ISmsi_int.exe: ClamAV-Test-File&lt;br /&gt;
clam_cache_emax.tgz: ClamAV-Test-File&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Telnet to port 3310 on the clamd machine:-&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;kjw-1:~ kieranwhitbread$ telnet clamd.example.com 3310&lt;br /&gt;
Trying 10.10.0.57...&lt;br /&gt;
Connected to clamd.example.com.&lt;br /&gt;
Escape character is '^]'.&lt;br /&gt;
STREAM&lt;br /&gt;
PORT 1480&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
make another telnet connection to that port number. submit the test string in and close the connection.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;kjw-1:~ kieranwhitbread$ telnet clamd.example.com 1480&lt;br /&gt;
Trying 10.10.0.57...&lt;br /&gt;
Connected to clamd.example.com.&lt;br /&gt;
Escape character is '^]'.&lt;br /&gt;
$CEliacmaTrESTuScikgsn$FREE-TEST-SIGNATURE$EEEEE$&lt;br /&gt;
^]&lt;br /&gt;
telnet&amp;gt; Connection closed.&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
look at the original connection. It should state that it found the test&lt;br /&gt;
signature.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;kjw-1:~ kieranwhitbread$ telnet clamd.example.com 3310&lt;br /&gt;
Trying 10.10.0.57...&lt;br /&gt;
Connected to clamd.example.com.&lt;br /&gt;
Escape character is '^]'.&lt;br /&gt;
STREAM&lt;br /&gt;
PORT 1480&lt;br /&gt;
stream: ClamAV-Test-Signature FOUND&lt;br /&gt;
Connection closed by foreign host.&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and an entry should be made in the clamd log&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;$ sudo grep ClamAV-Test-Signature /var/log/clamd&lt;br /&gt;
Mon Mar 28 17:42:13 2011 -&amp;gt; stream(138.37.8.42@1480): ClamAV-Test-Signature FOUND&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Squid_stats.py</id>
		<title>Squid stats.py</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Squid_stats.py"/>
				<updated>2011-07-16T12:58:50Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: New page: [[Redirect:Squid-Stats.py]]&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Redirect:Squid-Stats.py]]&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Thunderbird_debug</id>
		<title>Thunderbird debug</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Thunderbird_debug"/>
				<updated>2011-07-16T12:38:14Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: New page: [[Category:Linux]] [[Category:Desktop]]  Use this when thunderbird goes mad and you want to know why.  &amp;lt;nowiki&amp;gt; #!/bin/bash export NSPR_LOG_MODULES=IMAP:4,SMTP:4 export NSPR_LOG_FILE=~/Des...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Linux]]&lt;br /&gt;
[[Category:Desktop]]&lt;br /&gt;
&lt;br /&gt;
Use this when thunderbird goes mad and you want to know why.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
export NSPR_LOG_MODULES=IMAP:4,SMTP:4&lt;br /&gt;
export NSPR_LOG_FILE=~/Desktop/tbird.log&lt;br /&gt;
/Applications/Thunderbird.app/Contents/MacOS/thunderbird-bin&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Rpm-extract.sh</id>
		<title>Rpm-extract.sh</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Rpm-extract.sh"/>
				<updated>2011-07-16T12:33:44Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: New page: [[Category:linux]] [[Category:bash]] [[Category:scripts]]  Because I am too dumb to remember the correct switches for cpio   &amp;lt;nowiki&amp;gt; #!/bin/sh  rpm2cpio $1 | cpio -idmv &amp;lt;/nowiki&amp;gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:linux]]&lt;br /&gt;
[[Category:bash]]&lt;br /&gt;
[[Category:scripts]]&lt;br /&gt;
&lt;br /&gt;
Because I am too dumb to remember the correct switches for cpio&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
rpm2cpio $1 | cpio -idmv&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Eximstats.sh</id>
		<title>Eximstats.sh</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Eximstats.sh"/>
				<updated>2011-07-16T12:31:25Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:linux]]&lt;br /&gt;
[[Category:scripts]]&lt;br /&gt;
[[Category:bash]]&lt;br /&gt;
[[Category:perl]]&lt;br /&gt;
&lt;br /&gt;
Call this every night to generate a text based report for your exim server. It uses a little perl script to split the main log in to one log per complete day (from 00:00 hrs to 23:59 hrs). I use this to collect stats from multiple servers, then gather them centrally and convert them in to html reports.&lt;br /&gt;
&lt;br /&gt;
exim-main-log-split.pl:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/usr/bin/env perl&lt;br /&gt;
&lt;br /&gt;
# Take the exim log file specified as the first argument when calling this script, &lt;br /&gt;
# then split all entries in to seperate files for each day.&lt;br /&gt;
# also pipe logs in &lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
use File::Basename;&lt;br /&gt;
use POSIX;&lt;br /&gt;
&lt;br /&gt;
my $logtype = &amp;quot;main.log&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
my $previousDate = '';&lt;br /&gt;
my $currentDate = '';&lt;br /&gt;
my $logfile;&lt;br /&gt;
while (&amp;lt;&amp;gt;) {&lt;br /&gt;
    my $line = $_;&lt;br /&gt;
    $currentDate = '';&lt;br /&gt;
    if ($line =~ /^(\d{4}-\d{2}-\d{2}) .*/) {&lt;br /&gt;
        $currentDate = $1;&lt;br /&gt;
    }&lt;br /&gt;
    if ($currentDate ne $previousDate || !$logfile) {&lt;br /&gt;
        if ($logfile) {&lt;br /&gt;
            close($logfile);&lt;br /&gt;
        }&lt;br /&gt;
        open $logfile, &amp;quot;&amp;gt;&amp;gt;&amp;quot;, &amp;quot;$logtype.$currentDate&amp;quot; &lt;br /&gt;
            or die &amp;quot;Could not open $logtype.$currentDate: $!&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    print $logfile $line;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
eximstats.sh:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
# Generate daily reports from the exim-relay logs.&lt;br /&gt;
# scp the most recent report to www.exmple.com&lt;br /&gt;
# Remove existing reports older than seven days.&lt;br /&gt;
&lt;br /&gt;
LOG_FILE=/var/log/exim/main.log.1.bz2&lt;br /&gt;
LOG_SPLITTER=/usr/local/bin/exim-main-log-split.pl&lt;br /&gt;
&lt;br /&gt;
REPORT_DIR=/var/lib/exim/eximstats&lt;br /&gt;
&lt;br /&gt;
SCP_TARGET=eximstat@www.example.com:/var/lib/eximstat/$(hostname)&lt;br /&gt;
&lt;br /&gt;
DATE=$(date +%F)&lt;br /&gt;
REPORT_DATE=$(date --date '1 day ago' +%F)&lt;br /&gt;
&lt;br /&gt;
EXIMSTATS=/usr/bin/eximstats&lt;br /&gt;
&lt;br /&gt;
ARGS=&amp;quot;$(cat &amp;lt;&amp;lt;EOT&lt;br /&gt;
	-pattern Spam '/ rejected after DATA: Spam messages are not welcome here./' \&lt;br /&gt;
	-pattern Viruses '/ rejected after DATA: This message contains a virus/' \&lt;br /&gt;
EOT&lt;br /&gt;
)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [ ! -f $LOG_FILE ]; then&lt;br /&gt;
	echo Log file $LOG_FILE does not exist&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
cd $REPORT_DIR || exit 1&lt;br /&gt;
&lt;br /&gt;
bzcat $LOG_FILE | $LOG_SPLITTER &lt;br /&gt;
&lt;br /&gt;
$EXIMSTATS $ARGS -txt=$REPORT_DIR/$REPORT_DATE.txt $REPORT_DIR/main.log.$REPORT_DATE || exit&lt;br /&gt;
&lt;br /&gt;
rm $REPORT_DIR/main.log.$REPORT_DATE&lt;br /&gt;
&lt;br /&gt;
scp $REPORT_DATE.txt $SCP_TARGET/&lt;br /&gt;
&lt;br /&gt;
find $REPORT_DIR -name '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].txt' -ctime +14 | xargs rm &lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
eximstats-html-reports.sh (on www.example.com):&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#&lt;br /&gt;
# A script to generate eximstats reports from the exim main logs&lt;br /&gt;
# The logs are processed in to daily reports on the mailservers, &lt;br /&gt;
# before being copied over to this server each night&lt;br /&gt;
#&lt;br /&gt;
# This script depends on the mail servers' log rotation jobs, &lt;br /&gt;
# and their cron jobs that run aftwards to generate the daily &lt;br /&gt;
# reports&lt;br /&gt;
#&lt;br /&gt;
# The script creates daily, weekly and monthly reports. It also keeps &lt;br /&gt;
# the last copy of any given day, week or month to allow comaprisons.&lt;br /&gt;
#&lt;br /&gt;
# The script needs to run each day, it won't catch up if any days are&lt;br /&gt;
# missed. If that happens, weekly and monthly reports will still be&lt;br /&gt;
# created but won't be accurate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
################&lt;br /&gt;
# Configuration&lt;br /&gt;
&lt;br /&gt;
EXIMSTATS=/usr/local/bin/eximstats&lt;br /&gt;
#EXIMSTATS=/opt/local/sbin/eximstats&lt;br /&gt;
&lt;br /&gt;
MAIL_SERVERS=&amp;quot;foo bar baz&amp;quot;&lt;br /&gt;
&lt;br /&gt;
TEXT_REPORTS=&amp;quot;/var/lib/eximstat&amp;quot;&lt;br /&gt;
&lt;br /&gt;
CURRENT_REPORTS_DIR=/var/www/html/eximstats&lt;br /&gt;
PREVIOUS_REPORTS_DIR=&amp;quot;${CURRENT_REPORTS_DIR}/previous&amp;quot;&lt;br /&gt;
&lt;br /&gt;
NICENESS=39&lt;br /&gt;
&lt;br /&gt;
DAILY_REPORT_LABEL=daily&lt;br /&gt;
WEEKLY_REPORT_LABEL=weekly&lt;br /&gt;
MONTHLY_REPORT_LABEL=monthly&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
########################&lt;br /&gt;
# Options for eximstats&lt;br /&gt;
ARGS=&amp;quot;$(cat &amp;lt;&amp;lt;EOT&lt;br /&gt;
        -pattern Spam '/ rejected after DATA: Spam messages are not welcome here./' \&lt;br /&gt;
        -pattern Viruses '/ rejected after DATA: This message contains a virus/' \&lt;br /&gt;
        -ne \&lt;br /&gt;
        -nr \&lt;br /&gt;
        -charts \&lt;br /&gt;
        -merge&lt;br /&gt;
)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
############&lt;br /&gt;
# functions&lt;br /&gt;
&lt;br /&gt;
# date adjusts to the given number of days in the past and &lt;br /&gt;
# formatted using the provided formatting string&lt;br /&gt;
# usage: pastDate &amp;lt;minus no. days&amp;gt; &amp;lt;format&amp;gt;&lt;br /&gt;
pastDate()&lt;br /&gt;
{&lt;br /&gt;
    if [ ! $1 ]&lt;br /&gt;
    then&lt;br /&gt;
        exit 1&lt;br /&gt;
    fi&lt;br /&gt;
    if [ ! $2 ]&lt;br /&gt;
    then &lt;br /&gt;
        exit 1&lt;br /&gt;
    fi&lt;br /&gt;
    if [ `uname` = &amp;quot;Darwin&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        echo $(date -v -&amp;quot;$1&amp;quot;d +&amp;quot;$2&amp;quot;)&lt;br /&gt;
    fi&lt;br /&gt;
    if [ `uname` = &amp;quot;Linux&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        echo $(date --date=&amp;quot;$1 day ago&amp;quot; +&amp;quot;$2&amp;quot;)&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
##############################&lt;br /&gt;
# Directory Checks / Creation&lt;br /&gt;
&lt;br /&gt;
# Check required directories are writable - try to create them if missing or&lt;br /&gt;
# exit.&lt;br /&gt;
&lt;br /&gt;
if [ ! -d &amp;quot;${CURRENT_REPORTS_DIR}&amp;quot; -o ! -w &amp;quot;${CURRENT_REPORTS_DIR}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;The reports directory, &amp;quot;&lt;br /&gt;
    echo &amp;quot;'${CURRENT_REPORTS_DIR}',&amp;quot;&lt;br /&gt;
    echo &amp;quot;does not exist or is not writable&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
DAILY_DIR=&amp;quot;${CURRENT_REPORTS_DIR}/${DAILY_REPORT_LABEL}&amp;quot;&lt;br /&gt;
test -e &amp;quot;${DAILY_DIR}&amp;quot; || test -d &amp;quot;${DAILY_DIR}&amp;quot; || mkdir &amp;quot;${DAILY_DIR}&amp;quot;&lt;br /&gt;
if [ ! -d &amp;quot;${DAILY_DIR}&amp;quot; -o ! -w &amp;quot;${DAILY_DIR}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;The daily reports directory, &amp;quot;&lt;br /&gt;
    echo &amp;quot;'${DAILY_DIR}',&amp;quot;&lt;br /&gt;
    echo &amp;quot; does not exist or is not writable&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
WEEKLY_DIR=&amp;quot;${CURRENT_REPORTS_DIR}/${WEEKLY_REPORT_LABEL}&amp;quot;&lt;br /&gt;
test -e &amp;quot;${WEEKLY_DIR}&amp;quot; || test -d &amp;quot;${WEEKLY_DIR}&amp;quot; || mkdir &amp;quot;${WEEKLY_DIR}&amp;quot;&lt;br /&gt;
if [ ! -d &amp;quot;${WEEKLY_DIR}&amp;quot; -o ! -w &amp;quot;${WEEKLY_DIR}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;The monthly reports directory, &amp;quot;&lt;br /&gt;
    echo &amp;quot;'${WEEKLY_DIR}',&amp;quot;&lt;br /&gt;
    echo &amp;quot; does not exist or is not writable&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
MONTHLY_DIR=&amp;quot;${CURRENT_REPORTS_DIR}/${MONTHLY_REPORT_LABEL}&amp;quot;&lt;br /&gt;
test -e &amp;quot;${MONTHLY_DIR}&amp;quot; || test -d &amp;quot;${MONTHLY_DIR}&amp;quot; || mkdir &amp;quot;${MONTHLY_DIR}&amp;quot;&lt;br /&gt;
if [ ! -d &amp;quot;${MONTHLY_DIR}&amp;quot; -o ! -w &amp;quot;${MONTHLY_DIR}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;The monthly reports directory, &amp;quot;&lt;br /&gt;
    echo &amp;quot;'${MONTHLY_DIR}',&amp;quot;&lt;br /&gt;
    echo &amp;quot; does not exist or is not writable&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ ! -d &amp;quot;${PREVIOUS_REPORTS_DIR}&amp;quot; -o ! -w &amp;quot;${PREVIOUS_REPORTS_DIR}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;The previous reports directory, &amp;quot;&lt;br /&gt;
    echo &amp;quot;'${PREVIOUS_REPORTS_DIR}',&amp;quot;&lt;br /&gt;
    echo &amp;quot;does not exist or is not writable&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
PREV_DAILY_DIR=&amp;quot;${PREVIOUS_REPORTS_DIR}/${DAILY_REPORT_LABEL}&amp;quot;&lt;br /&gt;
test -e &amp;quot;${PREV_DAILY_DIR}&amp;quot; || test -d &amp;quot;${PREV_DAILY_DIR}&amp;quot; || mkdir &amp;quot;${PREV_DAILY_DIR}&amp;quot;&lt;br /&gt;
if [ ! -d &amp;quot;${PREV_DAILY_DIR}&amp;quot; -o ! -w &amp;quot;${PREV_DAILY_DIR}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;The daily reports directory, &amp;quot;&lt;br /&gt;
    echo &amp;quot;'${PREV_DAILY_DIR}',&amp;quot;&lt;br /&gt;
    echo &amp;quot; does not exist or is not writable&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
PREV_WEEKLY_DIR=&amp;quot;${PREVIOUS_REPORTS_DIR}/${WEEKLY_REPORT_LABEL}&amp;quot;&lt;br /&gt;
test -e &amp;quot;${PREV_WEEKLY_DIR}&amp;quot; || test -d &amp;quot;${PREV_WEEKLY_DIR}&amp;quot; || mkdir &amp;quot;${PREV_WEEKLY_DIR}&amp;quot;&lt;br /&gt;
if [ ! -d &amp;quot;${PREV_WEEKLY_DIR}&amp;quot; -o ! -w &amp;quot;${PREV_WEEKLY_DIR}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;The monthly reports directory, &amp;quot;&lt;br /&gt;
    echo &amp;quot;'${PREV_WEEKLY_DIR}',&amp;quot;&lt;br /&gt;
    echo &amp;quot; does not exist or is not writable&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
PREV_MONTHLY_DIR=&amp;quot;${PREVIOUS_REPORTS_DIR}/${MONTHLY_REPORT_LABEL}&amp;quot;&lt;br /&gt;
test -e &amp;quot;${PREV_MONTHLY_DIR}&amp;quot; || test -d &amp;quot;${PREV_MONTHLY_DIR}&amp;quot; || mkdir &amp;quot;${PREV_MONTHLY_DIR}&amp;quot;&lt;br /&gt;
if [ ! -d &amp;quot;${PREV_MONTHLY_DIR}&amp;quot; -o ! -w &amp;quot;${PREV_MONTHLY_DIR}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;The monthly reports directory, &amp;quot;&lt;br /&gt;
    echo &amp;quot;'${PREV_MONTHLY_DIR}',&amp;quot;&lt;br /&gt;
    echo &amp;quot; does not exist or is not writable&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
########&lt;br /&gt;
# Dates&lt;br /&gt;
&lt;br /&gt;
# these dates relate to the log files, i.e. yesterdays logs and activity.&lt;br /&gt;
DAY_OF_WEEK=$(pastDate 1 %w)&lt;br /&gt;
WEEK=$(pastDate 1 %U)&lt;br /&gt;
MONTH=$(pastDate 1 %m)&lt;br /&gt;
YEAR=$(pastDate 1 %Y)&lt;br /&gt;
DATE=$(pastDate 1 %F)&lt;br /&gt;
PREV_DATE=&amp;quot;$(($YEAR - 1))${DATE:(-6)}&amp;quot;&lt;br /&gt;
PREV_PREV_DATE=&amp;quot;$(($YEAR - 2))${DATE:(-6)}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# if today is the 1st of the month, then yesterday was the end of the month&lt;br /&gt;
MONTH_ENDED=$(&lt;br /&gt;
    test $(date +%d) = 01 &amp;amp;&amp;amp; echo true&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
###########################&lt;br /&gt;
# Create Daily HTML Report&lt;br /&gt;
&lt;br /&gt;
if [ -d &amp;quot;${DAILY_DIR}/${PREV_DATE}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;Moving previous Daily HTML report&amp;quot;&lt;br /&gt;
    [ -d &amp;quot;${PREV_DAILY_DIR}/${PREV_PREV_DATE}&amp;quot; ] &amp;amp;&amp;amp; rm -rf &amp;quot;${PREV_DAILY_DIR}/${PREV_PREV_DATE}&amp;quot;&lt;br /&gt;
    mv &amp;quot;${DAILY_DIR}/${PREV_DATE}&amp;quot; &amp;quot;${PREV_DAILY_DIR}/${PREV_DATE}&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating Daily HTML Report&amp;quot;&lt;br /&gt;
&lt;br /&gt;
mkdir -p &amp;quot;${DAILY_DIR}/${DATE}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
REPORT_LIST=&amp;quot;&amp;quot;&lt;br /&gt;
for server in $MAIL_SERVERS&lt;br /&gt;
do&lt;br /&gt;
    if [ -f &amp;quot;$TEXT_REPORTS/$server/$DATE.txt&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        REPORT_LIST=&amp;quot;$REPORT_LIST $TEXT_REPORTS/$server/$DATE.txt&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;WARNING: Missing report $TEXT_REPORTS/$server/$DATE.txt&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$REPORT_LIST&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    nice -n ${NICENESS} &amp;quot;${EXIMSTATS}&amp;quot; \&lt;br /&gt;
        ${ARGS} \&lt;br /&gt;
	    -chartdir &amp;quot;${DAILY_DIR}/${DATE}&amp;quot; \&lt;br /&gt;
	    -html=&amp;quot;${DAILY_DIR}/${DATE}/index.html&amp;quot; \&lt;br /&gt;
        $REPORT_LIST&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;WARNING: Unable to create merged relays report for $DATE. No reports found.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
echo&lt;br /&gt;
&lt;br /&gt;
#######################&lt;br /&gt;
# Create Weekly Report&lt;br /&gt;
&lt;br /&gt;
if [ $DAY_OF_WEEK -eq 6 ]&lt;br /&gt;
then&lt;br /&gt;
&lt;br /&gt;
    if [ -d &amp;quot;${WEEKLY_DIR}/${WEEK}&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        echo &amp;quot;Moving previous Weekly HTML report&amp;quot;&lt;br /&gt;
        if [ -d &amp;quot;${PREV_WEEKLY_DIR}/${WEEK}&amp;quot; ]&lt;br /&gt;
        then &lt;br /&gt;
            rm -rf &amp;quot;${PREV_WEEKLY_DIR}/${WEEK}&amp;quot;&lt;br /&gt;
        fi&lt;br /&gt;
        mv &amp;quot;${WEEKLY_DIR}/${WEEK}&amp;quot; &amp;quot;${PREV_WEEKLY_DIR}/${WEEK}&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    echo &amp;quot;Creating Weekly HTML Report&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    REPORT_LIST=&amp;quot;&amp;quot;&lt;br /&gt;
    DATE_ADJUSTMENT=$(( $DAY_OF_WEEK + 1 ))&lt;br /&gt;
    while [ $DATE_ADJUSTMENT -ge 1 ]&lt;br /&gt;
    do&lt;br /&gt;
        &lt;br /&gt;
        REPORT_DATE=$(pastDate $DATE_ADJUSTMENT %F)&lt;br /&gt;
        &lt;br /&gt;
        for server in $MAIL_SERVERS&lt;br /&gt;
        do&lt;br /&gt;
            if [ -f &amp;quot;${TEXT_REPORTS}/$server/${REPORT_DATE}.txt&amp;quot; ]&lt;br /&gt;
            then&lt;br /&gt;
                REPORT_LIST=&amp;quot;$REPORT_LIST $TEXT_REPORTS/$server/$REPORT_DATE.txt&amp;quot;&lt;br /&gt;
            else&lt;br /&gt;
                echo &amp;quot;WARNING: Missing report $TEXT_REPORTS/$server/$DATE.txt&amp;quot;&lt;br /&gt;
                continue&lt;br /&gt;
            fi&lt;br /&gt;
        done&lt;br /&gt;
        &lt;br /&gt;
        DATE_ADJUSTMENT=$(( $DATE_ADJUSTMENT - 1 ))&lt;br /&gt;
        &lt;br /&gt;
    done&lt;br /&gt;
&lt;br /&gt;
    if [ &amp;quot;$REPORT_LIST&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        mkdir -p &amp;quot;${WEEKLY_DIR}/${WEEK}&amp;quot;&lt;br /&gt;
        nice -n ${NICENESS} &amp;quot;${EXIMSTATS}&amp;quot; \&lt;br /&gt;
            ${ARGS} \&lt;br /&gt;
            -chartdir &amp;quot;${WEEKLY_DIR}/${WEEK}&amp;quot; \&lt;br /&gt;
            -html=&amp;quot;${WEEKLY_DIR}/${WEEK}/index.html&amp;quot; \&lt;br /&gt;
            $REPORT_LIST&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;WARNING: Unable to create merged relays report for week $WEEK. No reports found.&amp;quot;&lt;br /&gt;
    fi    &lt;br /&gt;
    &lt;br /&gt;
    echo&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
########################&lt;br /&gt;
# Create Monthly Report&lt;br /&gt;
&lt;br /&gt;
if [ $MONTH_ENDED ]&lt;br /&gt;
then&lt;br /&gt;
&lt;br /&gt;
    if [ -d &amp;quot;${MONTHLY_DIR}/${MONTH}&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        echo &amp;quot;Moving previous Monthly HTML report&amp;quot;&lt;br /&gt;
        if [ -d &amp;quot;${PREV_MONTHLY_DIR}/${MONTH}&amp;quot; ]&lt;br /&gt;
        then &lt;br /&gt;
            rm -rf &amp;quot;${PREV_MONTHLY_DIR}/${MONTH}&amp;quot;&lt;br /&gt;
        fi&lt;br /&gt;
        mv &amp;quot;${MONTHLY_DIR}/${MONTH}&amp;quot; &amp;quot;${PREV_MONTHLY_DIR}/${MONTH}&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    echo &amp;quot;Creating Monthly HTML Report&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    REPORT_LIST=&amp;quot;&amp;quot;&lt;br /&gt;
    for server in $MAIL_SERVERS&lt;br /&gt;
    do&lt;br /&gt;
        for REPORT in $(ls $TEXT_REPORTS/$server/${YEAR}-${MONTH}-*.txt)&lt;br /&gt;
        do&lt;br /&gt;
            REPORT_LIST=&amp;quot;$REPORT_LIST $REPORT&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        done&lt;br /&gt;
    done&lt;br /&gt;
&lt;br /&gt;
    if [ &amp;quot;$REPORT_LIST&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        &lt;br /&gt;
        mkdir -p &amp;quot;${MONTHLY_DIR}/${MONTH}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        nice -n ${NICENESS} &amp;quot;${EXIMSTATS}&amp;quot; \&lt;br /&gt;
            ${ARGS} \&lt;br /&gt;
            -chartdir &amp;quot;${MONTHLY_DIR}/${MONTH}&amp;quot; \&lt;br /&gt;
            -html=&amp;quot;${MONTHLY_DIR}/${MONTH}/index.html&amp;quot; \&lt;br /&gt;
            $REPORT_LIST&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
&lt;br /&gt;
        echo &amp;quot;WARNING: Unable to create merged relays report for month $MONTH. No reports found.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    fi&lt;br /&gt;
    &lt;br /&gt;
    echo&lt;br /&gt;
&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#########################&lt;br /&gt;
# Delete old cache files&lt;br /&gt;
&lt;br /&gt;
if [ $MONTH_ENDED ]&lt;br /&gt;
then&lt;br /&gt;
&lt;br /&gt;
    echo &amp;quot;Removing old text report files&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    cd &amp;quot;${TEXT_REPORTS}&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    if [ ${MONTH##0} -gt 1 ]&lt;br /&gt;
    then&lt;br /&gt;
        RM_MONTH=$(printf &amp;quot;%0#2d&amp;quot; $((${MONTH##0} - 1)) )&lt;br /&gt;
        RM_YEAR=$YEAR&lt;br /&gt;
    else&lt;br /&gt;
        RM_MONTH=12&lt;br /&gt;
        RM_YEAR=$(($YEAR - 1))&lt;br /&gt;
    fi&lt;br /&gt;
    &lt;br /&gt;
    for server in $MAIL_SERVERS&lt;br /&gt;
    do&lt;br /&gt;
        for REPORT_FILE in $(ls ${TEXT_REPORTS}/${server}/${RM_YEAR}-${RM_MONTH}-*.txt)&lt;br /&gt;
        do&lt;br /&gt;
            rm &amp;quot;${REPORT_FILE}&amp;quot;&lt;br /&gt;
        done&lt;br /&gt;
    done&lt;br /&gt;
    &lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Exim-linesforclient.sh</id>
		<title>Exim-linesforclient.sh</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Exim-linesforclient.sh"/>
				<updated>2011-07-16T12:26:09Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: New page: [[Category:linux]] [[Category:scripts]] [[Category:bash]]  Pass this an ip address for a client sending mail to your exim submission service   &amp;lt;nowiki&amp;gt; #!/bin/bash  cat /var/log/exim/main....&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:linux]]&lt;br /&gt;
[[Category:scripts]]&lt;br /&gt;
[[Category:bash]]&lt;br /&gt;
&lt;br /&gt;
Pass this an ip address for a client sending mail to your exim submission service&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
cat /var/log/exim/main.[0-9] | grep &amp;quot; \[$(echo $1 | sed -e 's/\./\\./g')\] &amp;quot;;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Exim-top-senders.sh</id>
		<title>Exim-top-senders.sh</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Exim-top-senders.sh"/>
				<updated>2011-07-16T12:24:08Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: New page: [[Category:linux]] [[Category:scripts]] [[Category:bash]]   &amp;lt;nowiki&amp;gt; #!/bin/bash  renice 10 $$  # Some nasty byte escape sequence showed up in an email address # \222 - possibly �� (La...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:linux]]&lt;br /&gt;
[[Category:scripts]]&lt;br /&gt;
[[Category:bash]]&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
renice 10 $$&lt;br /&gt;
&lt;br /&gt;
# Some nasty byte escape sequence showed up in an email address&lt;br /&gt;
# \222 - possibly �� (Latin Capital Letter Thorn)&lt;br /&gt;
export LC_ALL='C'&lt;br /&gt;
&lt;br /&gt;
cat /var/log/exim/main.[0-9] \&lt;br /&gt;
    | egrep &amp;quot;&amp;lt;[=\-] .* \[[^ ]+\] P=[a-z]*smtp.* &amp;quot; \&lt;br /&gt;
    | sed -e 's/^.* \[\(\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\}\)\] .*$/\1/' \&lt;br /&gt;
    | sort \&lt;br /&gt;
    | uniq -c \&lt;br /&gt;
    | sort -n \&lt;br /&gt;
    | tail -20&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Exim-incoming.sh</id>
		<title>Exim-incoming.sh</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Exim-incoming.sh"/>
				<updated>2011-07-16T12:22:23Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: New page: [[Category:linux]] [[Category:bash]] [[Category:scripts]]  $ exim-incoming.sh foo@example.com   &amp;lt;nowiki&amp;gt; #!/bin/bash  # return all details logged to the exim main log file for all messages...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:linux]]&lt;br /&gt;
[[Category:bash]]&lt;br /&gt;
[[Category:scripts]]&lt;br /&gt;
&lt;br /&gt;
$ exim-incoming.sh foo@example.com&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
# return all details logged to the exim main log file for all messages delivered to a particular email address&lt;br /&gt;
&lt;br /&gt;
grep -E &amp;quot;$(&lt;br /&gt;
	grep &amp;quot;=&amp;gt; [^ ]*@imap.example.com &amp;lt;$1&amp;quot; /var/log/exim/main.log \&lt;br /&gt;
	| cut -d\  -f 3 \&lt;br /&gt;
	| sort \&lt;br /&gt;
	| uniq \&lt;br /&gt;
	| tr &amp;quot;\n&amp;quot; &amp;quot;|&amp;quot; \&lt;br /&gt;
	| sed -e 's/|$//' &lt;br /&gt;
)&amp;quot; /var/log/exim-relay/main.log&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Cacti_ss_get_snmp</id>
		<title>Cacti ss get snmp</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Cacti_ss_get_snmp"/>
				<updated>2011-07-16T12:06:08Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:linux]]&lt;br /&gt;
[[Category:scripts]]&lt;br /&gt;
[[Category:PHP]]&lt;br /&gt;
&lt;br /&gt;
This is a script that will collect arbitary snmp data for cacti's script host.  You specificy which oids to query in named sections of an ini file, and pass the name of the particular dataset you want in as an argument when calling the script.&lt;br /&gt;
&lt;br /&gt;
This means you can start collecting and graphing data for new things on your network with out necessarily needing to write a new script to get the data.&lt;br /&gt;
&lt;br /&gt;
This script is based on the work of the Cacti developers and contributors to the cacti project. It's licensed under the same GNU General Public License.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
// Cacti Script Server boiler-plate:&lt;br /&gt;
&lt;br /&gt;
/* do NOT run this script through a web browser */&lt;br /&gt;
if (!isset($_SERVER[&amp;quot;argv&amp;quot;][0]) || isset($_SERVER['REQUEST_METHOD'])  || isset($_SERVER['REMOTE_ADDR'])) {&lt;br /&gt;
    die(&amp;quot;&amp;lt;br&amp;gt;&amp;lt;strong&amp;gt;This script is only meant to run at the command line.&amp;lt;/strong&amp;gt;&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$no_http_headers = true;&lt;br /&gt;
&lt;br /&gt;
/* display No errors */&lt;br /&gt;
ini_set('display_errors', 1);&lt;br /&gt;
&lt;br /&gt;
if (isset($config)) {&lt;br /&gt;
    include_once(dirname(__FILE__) . &amp;quot;/../lib/snmp.php&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if (!isset($called_by_script_server)) {&lt;br /&gt;
    include_once(dirname(__FILE__) . &amp;quot;/../include/global.php&amp;quot;);&lt;br /&gt;
    include_once(dirname(__FILE__) . &amp;quot;/../lib/snmp.php&amp;quot;);&lt;br /&gt;
    &lt;br /&gt;
    array_shift($_SERVER[&amp;quot;argv&amp;quot;]);&lt;br /&gt;
    $functionName = $_SERVER[&amp;quot;argv&amp;quot;][0];&lt;br /&gt;
    array_shift($_SERVER[&amp;quot;argv&amp;quot;]);&lt;br /&gt;
    &lt;br /&gt;
    print call_user_func_array($functionName, $_SERVER[&amp;quot;argv&amp;quot;]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * SETTINGS&lt;br /&gt;
 */&lt;br /&gt;
define('SS_GET_SNMP_INI', '/etc/cacti/ss_get_snmp.ini');&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// http://www.php.net/manual/en/function.sys-get-temp-dir.php#85261&lt;br /&gt;
if (!function_exists(&amp;quot;sys_get_temp_dir&amp;quot;)) {&lt;br /&gt;
  function sys_get_temp_dir() {&lt;br /&gt;
      if( $temp=getenv('TMP') )        return $temp;&lt;br /&gt;
      if( $temp=getenv('TEMP') )        return $temp;&lt;br /&gt;
      if( $temp=getenv('TMPDIR') )    return $temp;&lt;br /&gt;
      $temp=tempnam(__FILE__,'');&lt;br /&gt;
      if (file_exists($temp)) {&lt;br /&gt;
          unlink($temp);&lt;br /&gt;
          return dirname($temp);&lt;br /&gt;
      }&lt;br /&gt;
      return null;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function ss_get_snmp_config($query) {&lt;br /&gt;
    static $config;&lt;br /&gt;
    if (!$config) {&lt;br /&gt;
        $config = parse_ini_file(SS_GET_SNMP_INI, true);&lt;br /&gt;
    }&lt;br /&gt;
    return (is_array($config) &amp;amp;&amp;amp; isset($config[$query])) ? $config[$query] : null;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Query a group of snmp oids and specified in the ini configuration file for this script&lt;br /&gt;
 *&lt;br /&gt;
 * @param string $query a query name specified in the ss_get_snmp.ini configuration file&lt;br /&gt;
 * @param string $hostname the hostname or ipaddress of the snmp server&lt;br /&gt;
 * @param string $snmpauth colon delimited list of snmp connection parameters&lt;br /&gt;
 * @return null&lt;br /&gt;
 **/&lt;br /&gt;
function ss_get_snmp($query, $hostname, $snmpauth)&lt;br /&gt;
{&lt;br /&gt;
    $results = null;&lt;br /&gt;
    $walk    = false;&lt;br /&gt;
    $oids    = ss_get_snmp_config($query);&lt;br /&gt;
    if (!$oids) {&lt;br /&gt;
        trigger_error(&amp;quot;Not such query: $query&amp;quot;, E_USER_WARNING);&lt;br /&gt;
        return null;&lt;br /&gt;
    }&lt;br /&gt;
    if (isset($oids['__walk']) &amp;amp;&amp;amp; $oids['__walk']) {&lt;br /&gt;
        $walk = true;&lt;br /&gt;
        unset($oids['__walk']);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    $polling_interval = read_config_option(&amp;quot;poller_interval&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    $temp_dir = sys_get_temp_dir() . &amp;quot;/&amp;quot; . basename(__FILE__);&lt;br /&gt;
    $temp_dir = preg_replace('/\.php$/', '', $temp_dir);&lt;br /&gt;
    if (!is_dir($temp_dir)) {&lt;br /&gt;
        mkdir($temp_dir);&lt;br /&gt;
    }&lt;br /&gt;
    if (!is_dir($temp_dir.&amp;quot;/$query&amp;quot;)) {&lt;br /&gt;
        mkdir($temp_dir.&amp;quot;/$query&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    $temp_dir = &amp;quot;$temp_dir/$query&amp;quot;;&lt;br /&gt;
    if (is_file(&amp;quot;$temp_dir/$hostname&amp;quot;)) {&lt;br /&gt;
        $cache_stats = stat(&amp;quot;$temp_dir/$hostname&amp;quot;);&lt;br /&gt;
        if ( (($cache_stats['mtime'] + $polling_interval) * 0.75) &amp;gt; time() ) {&lt;br /&gt;
            if ($cache = fopen(&amp;quot;$temp_dir/$hostname&amp;quot;, 'r')) {&lt;br /&gt;
                while (!feof($cache)) {&lt;br /&gt;
                    $results .= fgets($cache);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    if (strlen($results)) {&lt;br /&gt;
        return $results;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    $results = ss_get_snmp_query($oids, $hostname, $snmpauth, $walk);&lt;br /&gt;
&lt;br /&gt;
    if (is_file(&amp;quot;$temp_dir/$hostname&amp;quot;) &amp;amp;&amp;amp; !is_writable(&amp;quot;$temp_dir/$hostname&amp;quot;)) {&lt;br /&gt;
        unlink(&amp;quot;$temp_dir/$hostname&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    file_put_contents(&amp;quot;$temp_dir/$hostname&amp;quot;, $results);&lt;br /&gt;
&lt;br /&gt;
    return $results;&lt;br /&gt;
    //return (strlen($results)) ? true : false;&lt;br /&gt;
}&lt;br /&gt;
/**&lt;br /&gt;
 * generic function to fetch a list of oids and output the results&lt;br /&gt;
 * in cacti scripts servers fieldname:value format&lt;br /&gt;
 *&lt;br /&gt;
 * @param array $oids an assiative array of oids to query. The array keys are used as the field names for cacti in the results.&lt;br /&gt;
 * @param string $hostname the hostname or ipaddress of the snmp server&lt;br /&gt;
 * @param string $snmpauth colon delimited list of snmp connection parameters&lt;br /&gt;
 * @param bool $walk if true, use snmp walk to fetch data, otherwise use snmp get&lt;br /&gt;
 *&lt;br /&gt;
 * @return string&lt;br /&gt;
 **/&lt;br /&gt;
function ss_get_snmp_query($query, $hostname, $snmpauth, $walk=false)&lt;br /&gt;
{&lt;br /&gt;
    $snmp = explode(&amp;quot;:&amp;quot;, $snmpauth);&lt;br /&gt;
    $snmp_version   = $snmp[0];&lt;br /&gt;
    $snmp_port      = $snmp[1];&lt;br /&gt;
    $snmp_timeout   = $snmp[2];&lt;br /&gt;
    $ping_retries   = (strlen($snmp[3]) ? $snmp[3] : 0);&lt;br /&gt;
    $max_oids       = (strlen($snmp[4]) ? $snmp[4] : 0);&lt;br /&gt;
&lt;br /&gt;
    $snmp_auth_username     = &amp;quot;&amp;quot;;&lt;br /&gt;
    $snmp_auth_password     = &amp;quot;&amp;quot;;&lt;br /&gt;
    $snmp_auth_protocol     = &amp;quot;&amp;quot;;&lt;br /&gt;
    $snmp_priv_passphrase   = &amp;quot;&amp;quot;;&lt;br /&gt;
    $snmp_priv_protocol     = &amp;quot;&amp;quot;;&lt;br /&gt;
    $snmp_context           = &amp;quot;&amp;quot;;&lt;br /&gt;
    $snmp_community         = &amp;quot;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
    if ($snmp_version == 3) &lt;br /&gt;
    {&lt;br /&gt;
        $snmp_auth_username   = isset($snmp[6])  ? $snmp[6]  : &amp;quot;&amp;quot;;&lt;br /&gt;
        $snmp_auth_password   = isset($snmp[7])  ? $snmp[7]  : &amp;quot;&amp;quot;;&lt;br /&gt;
        $snmp_auth_protocol   = isset($snmp[8])  ? $snmp[8]  : &amp;quot;&amp;quot;;&lt;br /&gt;
        $snmp_priv_passphrase = isset($snmp[9])  ? $snmp[9]  : &amp;quot;&amp;quot;;&lt;br /&gt;
        $snmp_priv_protocol   = isset($snmp[10]) ? $snmp[10] : &amp;quot;&amp;quot;;&lt;br /&gt;
        $snmp_context         = isset($snmp[11]) ? $snmp[11] : &amp;quot;&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    else&lt;br /&gt;
    {&lt;br /&gt;
        $snmp_community = isset($snmp[5]) ? $snmp[5] : &amp;quot;&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    $output = '';&lt;br /&gt;
    $cacti_snmp_func = $walk ? &amp;quot;cacti_snmp_walk&amp;quot; : &amp;quot;cacti_snmp_get&amp;quot;;&lt;br /&gt;
    foreach ($query as $name =&amp;gt; $oid)&lt;br /&gt;
    {&lt;br /&gt;
        $results = $cacti_snmp_func($hostname, $snmp_community, &lt;br /&gt;
                $oid, $snmp_version, $snmp_auth_username, &lt;br /&gt;
                $snmp_auth_password, $snmp_auth_protocol, &lt;br /&gt;
                $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, &lt;br /&gt;
                $snmp_port, $snmp_timeout, $ping_retries, $max_oids, &lt;br /&gt;
                SNMP_POLLER&lt;br /&gt;
            );&lt;br /&gt;
        if ($walk)&lt;br /&gt;
        {&lt;br /&gt;
            for ($i = 0; $i &amp;lt; sizeof($results); ++$i)&lt;br /&gt;
            {&lt;br /&gt;
                $output .= $name . ($walk ? ($i + 1) : null) . &amp;quot;:&amp;quot; . &lt;br /&gt;
                    $results[$i]['value'] . &amp;quot; &amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
            $output .= &amp;quot;$name:$results &amp;quot;;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    return trim($output);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Squid-Stats.py</id>
		<title>Squid-Stats.py</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Squid-Stats.py"/>
				<updated>2011-07-16T11:59:54Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: New page: [[Category:linux]] [[Category:python]] [[Category:scripts]]  This script will use a local squidclient binary to get stats from squid's cache manager and output them in a way cacti can use ...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:linux]]&lt;br /&gt;
[[Category:python]]&lt;br /&gt;
[[Category:scripts]]&lt;br /&gt;
&lt;br /&gt;
This script will use a local squidclient binary to get stats from squid's cache manager and output them in a way cacti can use them. I haven't included the cacti data and graph templates. I might do that at some point.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
squidclient = &amp;quot;/usr/local/bin/squidclient&amp;quot;&lt;br /&gt;
tmpdir = &amp;quot;/tmp/squid_stats&amp;quot;&lt;br /&gt;
&lt;br /&gt;
import cPickle, optparse, os, subprocess, sys, time&lt;br /&gt;
&lt;br /&gt;
def cache_stats(stats, hostname, tmpdir):&lt;br /&gt;
    try:&lt;br /&gt;
        os.makedirs(tmpdir, 0755)&lt;br /&gt;
    except:&lt;br /&gt;
        pass&lt;br /&gt;
    try:&lt;br /&gt;
        cache = open(tmpdir + &amp;quot;/&amp;quot; + hostname, 'w')&lt;br /&gt;
        cPickle.dump(stats, cache)&lt;br /&gt;
    except:&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
def fetch_cached_stats(hostname, pollerInterval, tmpdir):&lt;br /&gt;
    mtime = 0&lt;br /&gt;
    cacheFile = tmpdir + '/' + hostname&lt;br /&gt;
    cacheLifetime = pollerInterval * 0.75&lt;br /&gt;
    now = time.time()&lt;br /&gt;
    try:&lt;br /&gt;
        mtime = os.stat(cacheFile).st_mtime&lt;br /&gt;
        if 0 &amp;lt; mtime &amp;gt; (now - cacheLifetime):&lt;br /&gt;
            cache = open(cacheFile, 'r')&lt;br /&gt;
            stats = cPickle.load(cache)&lt;br /&gt;
            cache.close()&lt;br /&gt;
            return stats&lt;br /&gt;
    except:&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
def fetch_stats(argsList):&lt;br /&gt;
    squid5min = subprocess.Popen(argsList + ['mgr:5min'], stdout=subprocess.PIPE).communicate()[0]&lt;br /&gt;
    if len(squid5min):&lt;br /&gt;
	    return squid5min&lt;br /&gt;
    else:&lt;br /&gt;
	    return False&lt;br /&gt;
&lt;br /&gt;
def filter_stats(stats, query):&lt;br /&gt;
    queries = {&lt;br /&gt;
        &amp;quot;requests&amp;quot;: [&lt;br /&gt;
            &amp;quot;aborted_requests&amp;quot;,&lt;br /&gt;
            &amp;quot;client_http.requests&amp;quot;,&lt;br /&gt;
            &amp;quot;client_http.hits&amp;quot;,&lt;br /&gt;
            &amp;quot;client_http.errors&amp;quot;, &lt;br /&gt;
            &amp;quot;server.all.requests&amp;quot;, &lt;br /&gt;
            &amp;quot;server.all.errors&amp;quot;, &lt;br /&gt;
            &amp;quot;server.http.requests&amp;quot;,&lt;br /&gt;
            &amp;quot;server.http.errors&amp;quot;,&lt;br /&gt;
            &amp;quot;server.ftp.requests&amp;quot;,&lt;br /&gt;
            &amp;quot;server.ftp.errors&amp;quot;, &lt;br /&gt;
            &amp;quot;server.other.requests&amp;quot;,&lt;br /&gt;
            &amp;quot;server.other.errors&amp;quot;,&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;transfer&amp;quot;: [&lt;br /&gt;
            &amp;quot;server.all.kbytes_in&amp;quot;,  &lt;br /&gt;
            &amp;quot;server.all.kbytes_out&amp;quot;, &lt;br /&gt;
            &amp;quot;server.http.kbytes_in&amp;quot;, &lt;br /&gt;
            &amp;quot;server.http.kbytes_out&amp;quot;,&lt;br /&gt;
            &amp;quot;server.ftp.kbytes_in&amp;quot;,  &lt;br /&gt;
            &amp;quot;server.ftp.kbytes_out&amp;quot;, &lt;br /&gt;
            &amp;quot;server.other.kbytes_in&amp;quot;,&lt;br /&gt;
            &amp;quot;server.other.kbytes_out&amp;quot;,&lt;br /&gt;
            &amp;quot;client_http.kbytes_in&amp;quot;, &lt;br /&gt;
            &amp;quot;client_http.kbytes_out&amp;quot;, &lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;svctime&amp;quot;: [&lt;br /&gt;
            &amp;quot;client_http.all_median_svc_time&amp;quot;,&lt;br /&gt;
            &amp;quot;client_http.miss_median_svc_time&amp;quot;,&lt;br /&gt;
            &amp;quot;client_http.nm_median_svc_time&amp;quot;, &lt;br /&gt;
            &amp;quot;client_http.nh_median_svc_time&amp;quot;, &lt;br /&gt;
            &amp;quot;client_http.hit_median_svc_time&amp;quot;,&lt;br /&gt;
            &amp;quot;dns.median_svc_time&amp;quot;,            &lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;syscallsdisk&amp;quot;: [&lt;br /&gt;
            &amp;quot;syscalls.disk.opens&amp;quot;, &lt;br /&gt;
            &amp;quot;syscalls.disk.closes&amp;quot;,&lt;br /&gt;
            &amp;quot;syscalls.disk.reads&amp;quot;, &lt;br /&gt;
            &amp;quot;syscalls.disk.writes&amp;quot;,&lt;br /&gt;
            &amp;quot;syscalls.disk.seeks&amp;quot;, &lt;br /&gt;
            &amp;quot;syscalls.disk.unlinks&amp;quot;,&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;syscallssocket&amp;quot;: [&lt;br /&gt;
            &amp;quot;syscalls.sock.accepts&amp;quot;, &lt;br /&gt;
            &amp;quot;syscalls.sock.sockets&amp;quot;, &lt;br /&gt;
            &amp;quot;syscalls.sock.connects&amp;quot;, &lt;br /&gt;
            &amp;quot;syscalls.sock.binds&amp;quot;,   &lt;br /&gt;
            &amp;quot;syscalls.sock.closes&amp;quot;,  &lt;br /&gt;
            &amp;quot;syscalls.sock.reads&amp;quot;,   &lt;br /&gt;
            &amp;quot;syscalls.sock.writes&amp;quot;,  &lt;br /&gt;
            &amp;quot;syscalls.sock.recvfroms&amp;quot;,&lt;br /&gt;
            &amp;quot;syscalls.sock.sendtos&amp;quot;, &lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;swap&amp;quot;: [&lt;br /&gt;
            &amp;quot;swap.outs&amp;quot;,        &lt;br /&gt;
            &amp;quot;swap.ins&amp;quot;,         &lt;br /&gt;
            &amp;quot;swap.files_cleaned&amp;quot;,&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;unlink&amp;quot;: [&lt;br /&gt;
            &amp;quot;unlink.requests&amp;quot;,&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;pagefaults&amp;quot;: [&lt;br /&gt;
            &amp;quot;page_faults&amp;quot;,&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;selectloops&amp;quot;: [&lt;br /&gt;
            &amp;quot;select_loops&amp;quot;,           &lt;br /&gt;
            &amp;quot;select_fds&amp;quot;,             &lt;br /&gt;
            &amp;quot;average_select_fd_period&amp;quot;,      &lt;br /&gt;
            &amp;quot;median_select_fds&amp;quot;,      &lt;br /&gt;
        ],&lt;br /&gt;
    }&lt;br /&gt;
    filteredStats = {}&lt;br /&gt;
    for item in queries[query]:&lt;br /&gt;
        if stats.has_key(item):&lt;br /&gt;
            filteredStats[item] = stats[item]&lt;br /&gt;
    return filteredStats&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def output_stats(stats):&lt;br /&gt;
    numStats = len(stats)&lt;br /&gt;
    for stat in stats:&lt;br /&gt;
	numStats -= 1&lt;br /&gt;
	output = &amp;quot;%s:&amp;quot; % (stat.replace('.', '_'), )&lt;br /&gt;
    	if stats[stat] == &amp;quot;U&amp;quot;:&lt;br /&gt;
            output = output + &amp;quot;U&amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
	    output = output + (&amp;quot;%.2f&amp;quot; % (float(stats[stat]), ))&lt;br /&gt;
        sys.stdout.write(output)&lt;br /&gt;
        if numStats &amp;gt; 0:&lt;br /&gt;
            sys.stdout.write(&amp;quot; &amp;quot;)&lt;br /&gt;
&lt;br /&gt;
def parse_stats(commandOutput, stats):&lt;br /&gt;
    for line in commandOutput.splitlines():&lt;br /&gt;
        try:&lt;br /&gt;
            name, value = line.split(&amp;quot; = &amp;quot;)&lt;br /&gt;
        except:&lt;br /&gt;
            continue&lt;br /&gt;
        if stats.has_key(name):&lt;br /&gt;
            length = value.find('/') &lt;br /&gt;
            if length &amp;lt; 0:&lt;br /&gt;
                length = value.find(' ')&lt;br /&gt;
            if length &amp;lt; 0:&lt;br /&gt;
                length = value.find('%')&lt;br /&gt;
            if length &amp;lt; 0:&lt;br /&gt;
                length = None&lt;br /&gt;
            stats[name] = value[0:length]&lt;br /&gt;
    return stats&lt;br /&gt;
&lt;br /&gt;
def parse_options(parser):&lt;br /&gt;
    (options, args) = parser.parse_args()&lt;br /&gt;
    argsList = [squidclient]&lt;br /&gt;
    if options.hostname:&lt;br /&gt;
        argsList += ['-h', options.hostname]&lt;br /&gt;
    if options.port:&lt;br /&gt;
        argsList += ['-p', options.port]&lt;br /&gt;
    if options.bind:&lt;br /&gt;
        argsList += ['-l', options.bind]&lt;br /&gt;
    if options.timeout:&lt;br /&gt;
        argsList += ['-T', options.timeout]&lt;br /&gt;
    if options.username:&lt;br /&gt;
        argsList += ['-u', options.username]&lt;br /&gt;
    if options.password:&lt;br /&gt;
        argsList += ['-w', options.password]&lt;br /&gt;
    return argsList, options&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
parser = optparse.OptionParser()&lt;br /&gt;
parser.add_option(&amp;quot;-H&amp;quot;, dest=&amp;quot;hostname&amp;quot;, &lt;br /&gt;
	help=&amp;quot;Retrieve URL from cache on hostname.  Default is localhost.&amp;quot;,&lt;br /&gt;
	default=&amp;quot;localhost&amp;quot;)&lt;br /&gt;
parser.add_option(&amp;quot;-l&amp;quot;, dest=&amp;quot;bind&amp;quot;,     &lt;br /&gt;
	help=&amp;quot;Specify a local IP address to bind to.  Default is none.&amp;quot;)&lt;br /&gt;
parser.add_option(&amp;quot;-p&amp;quot;, dest=&amp;quot;port&amp;quot;,     &lt;br /&gt;
	help=&amp;quot;Port number of cache.  Default is 3128.&amp;quot;, &lt;br /&gt;
	default=&amp;quot;3128&amp;quot;)&lt;br /&gt;
parser.add_option(&amp;quot;-T&amp;quot;, dest=&amp;quot;timeout&amp;quot;,  &lt;br /&gt;
	help=&amp;quot;Timeout value (seconds) for read/write operations.&amp;quot;,&lt;br /&gt;
	default=&amp;quot;7&amp;quot;)&lt;br /&gt;
parser.add_option(&amp;quot;-u&amp;quot;, dest=&amp;quot;username&amp;quot;, &lt;br /&gt;
	help=&amp;quot;Proxy authentication username&amp;quot;)&lt;br /&gt;
parser.add_option(&amp;quot;-w&amp;quot;, dest=&amp;quot;password&amp;quot;, &lt;br /&gt;
	help=&amp;quot;Proxy authentication password&amp;quot;)&lt;br /&gt;
parser.add_option(&amp;quot;-P&amp;quot;, dest=&amp;quot;pollerInterval&amp;quot;,&lt;br /&gt;
    help=&amp;quot;The polling interval used by Cacti&amp;quot;,&lt;br /&gt;
    default=300, type=&amp;quot;int&amp;quot;)&lt;br /&gt;
parser.add_option(&amp;quot;-q&amp;quot;, dest=&amp;quot;query&amp;quot;,&lt;br /&gt;
    help=&amp;quot;The query to run&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
argsList, options = parse_options(parser)&lt;br /&gt;
&lt;br /&gt;
stats = {&lt;br /&gt;
        &amp;quot;client_http.requests&amp;quot;:             0,&lt;br /&gt;
        &amp;quot;client_http.hits&amp;quot;:                 0,&lt;br /&gt;
        &amp;quot;client_http.errors&amp;quot;:               0,&lt;br /&gt;
        &amp;quot;server.all.requests&amp;quot;:              0,&lt;br /&gt;
        &amp;quot;server.all.errors&amp;quot;:                0,&lt;br /&gt;
        &amp;quot;server.http.requests&amp;quot;:             0,&lt;br /&gt;
        &amp;quot;server.http.errors&amp;quot;:               0,&lt;br /&gt;
        &amp;quot;server.ftp.requests&amp;quot;:              0,&lt;br /&gt;
        &amp;quot;server.ftp.errors&amp;quot;:                0,&lt;br /&gt;
        &amp;quot;server.other.requests&amp;quot;:            0,&lt;br /&gt;
        &amp;quot;server.other.errors&amp;quot;:              0,&lt;br /&gt;
        &amp;quot;server.all.kbytes_in&amp;quot;:             0,&lt;br /&gt;
        &amp;quot;server.all.kbytes_out&amp;quot;:            0,&lt;br /&gt;
        &amp;quot;server.http.kbytes_in&amp;quot;:            0,&lt;br /&gt;
        &amp;quot;server.http.kbytes_out&amp;quot;:           0,&lt;br /&gt;
        &amp;quot;server.ftp.kbytes_in&amp;quot;:             0,&lt;br /&gt;
        &amp;quot;server.ftp.kbytes_out&amp;quot;:            0,&lt;br /&gt;
        &amp;quot;server.other.kbytes_in&amp;quot;:           0,&lt;br /&gt;
        &amp;quot;server.other.kbytes_out&amp;quot;:          0,&lt;br /&gt;
        &amp;quot;client_http.kbytes_in&amp;quot;:            0,&lt;br /&gt;
        &amp;quot;client_http.kbytes_out&amp;quot;:           0,&lt;br /&gt;
        &amp;quot;client_http.all_median_svc_time&amp;quot;:  0,&lt;br /&gt;
        &amp;quot;client_http.miss_median_svc_time&amp;quot;: 0,&lt;br /&gt;
        &amp;quot;client_http.nm_median_svc_time&amp;quot;:   0,&lt;br /&gt;
        &amp;quot;client_http.nh_median_svc_time&amp;quot;:   0,&lt;br /&gt;
        &amp;quot;client_http.hit_median_svc_time&amp;quot;:  0,&lt;br /&gt;
        &amp;quot;dns.median_svc_time&amp;quot;:              0,&lt;br /&gt;
        &amp;quot;unlink.requests&amp;quot;:                  0,&lt;br /&gt;
        &amp;quot;page_faults&amp;quot;:                      0,&lt;br /&gt;
        &amp;quot;select_loops&amp;quot;:                     0,&lt;br /&gt;
        &amp;quot;select_fds&amp;quot;:                       0,&lt;br /&gt;
        &amp;quot;average_select_fd_period&amp;quot;:         0,       &lt;br /&gt;
        &amp;quot;median_select_fds&amp;quot;:                0,&lt;br /&gt;
        &amp;quot;swap.outs&amp;quot;:                        0,&lt;br /&gt;
        &amp;quot;swap.ins&amp;quot;:                         0,&lt;br /&gt;
        &amp;quot;swap.files_cleaned&amp;quot;:               0, &lt;br /&gt;
        &amp;quot;aborted_requests&amp;quot;:                 0,&lt;br /&gt;
        &amp;quot;syscalls.disk.opens&amp;quot;:              0,&lt;br /&gt;
        &amp;quot;syscalls.disk.closes&amp;quot;:             0,&lt;br /&gt;
        &amp;quot;syscalls.disk.reads&amp;quot;:              0,&lt;br /&gt;
        &amp;quot;syscalls.disk.writes&amp;quot;:             0,&lt;br /&gt;
        &amp;quot;syscalls.disk.seeks&amp;quot;:              0,&lt;br /&gt;
        &amp;quot;syscalls.disk.unlinks&amp;quot;:            0,&lt;br /&gt;
        &amp;quot;syscalls.sock.accepts&amp;quot;:            0,&lt;br /&gt;
        &amp;quot;syscalls.sock.sockets&amp;quot;:            0,&lt;br /&gt;
        &amp;quot;syscalls.sock.connects&amp;quot;:           0, &lt;br /&gt;
        &amp;quot;syscalls.sock.binds&amp;quot;:              0,&lt;br /&gt;
        &amp;quot;syscalls.sock.closes&amp;quot;:             0,&lt;br /&gt;
        &amp;quot;syscalls.sock.reads&amp;quot;:              0,&lt;br /&gt;
        &amp;quot;syscalls.sock.writes&amp;quot;:             0,&lt;br /&gt;
        &amp;quot;syscalls.sock.recvfroms&amp;quot;:          0,&lt;br /&gt;
        &amp;quot;syscalls.sock.sendtos&amp;quot;:            0,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
cachedStats = fetch_cached_stats(options.hostname, options.pollerInterval, tmpdir)&lt;br /&gt;
if cachedStats:&lt;br /&gt;
    output_stats(filter_stats(cachedStats, options.query))&lt;br /&gt;
else:&lt;br /&gt;
    squid5min = fetch_stats(argsList)&lt;br /&gt;
    if squid5min == False:&lt;br /&gt;
        for stat in stats:&lt;br /&gt;
            stats[stat] = &amp;quot;U&amp;quot;&lt;br /&gt;
    else:&lt;br /&gt;
        stats = parse_stats(squid5min, stats)&lt;br /&gt;
        cache_stats(stats, options.hostname, tmpdir)&lt;br /&gt;
    output_stats(filter_stats(stats, options.query))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Squid-Stats.sh</id>
		<title>Squid-Stats.sh</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Squid-Stats.sh"/>
				<updated>2011-07-16T11:56:32Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:bash]]&lt;br /&gt;
[[Category:linux]]&lt;br /&gt;
[[Category:scripts]]&lt;br /&gt;
&lt;br /&gt;
This was a poor attempt to collect squid stats from the cache manager and get them in to cacti. I wrote some python to do this and it's much better, see [[Squid-Stats.py]]. I can't even remember if I managed to finished this script. It's here to remind me that some things shouldn't be attempted in bash because it's a waste of time.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
STATS_DIR=/var/lib/squid-stats&lt;br /&gt;
&lt;br /&gt;
CLIENT=/opt/local/bin/squidclient&lt;br /&gt;
&lt;br /&gt;
HOST=wwwcache.qmul.ac.uk&lt;br /&gt;
PORT=3128&lt;br /&gt;
URL_FD=mgr:filedescriptors&lt;br /&gt;
URL_INFO=mgr:info&lt;br /&gt;
URL_CLIENTS=mgr:client_list&lt;br /&gt;
URL_PCONN=mgr:pconn&lt;br /&gt;
URL_AVG60=mgr:60min&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
DATE=$(date +%F)&lt;br /&gt;
mkdir &amp;quot;${STATS_DIR}/${DATE}&amp;quot;&lt;br /&gt;
STATS_FILE=&amp;quot;${STATS_DIR}/${DATE}/summary&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function fetch_stats() {&lt;br /&gt;
	URL=&amp;quot;$1&amp;quot;&lt;br /&gt;
	&amp;quot;$CLIENT&amp;quot; -h &amp;quot;$HOST&amp;quot; -p &amp;quot;$PORT&amp;quot; &amp;quot;$URL&amp;quot; &amp;gt; &amp;quot;${STATS_DIR}/${DATE}/${URL#mgr:}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
function add_s() {&lt;br /&gt;
	NAME=&amp;quot;$1&amp;quot;&lt;br /&gt;
	VALUE=&amp;quot;$2&amp;quot;&lt;br /&gt;
	echo &amp;quot;$NAME $VALUE&amp;quot; &amp;gt;&amp;gt; &amp;quot;$STATS_FILE&amp;quot;	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
fetch_stats &amp;quot;$URL_FD&amp;quot;      &lt;br /&gt;
fetch_stats &amp;quot;$URL_INFO&amp;quot;    &lt;br /&gt;
fetch_stats &amp;quot;$URL_CLIENTS&amp;quot; &lt;br /&gt;
fetch_stats &amp;quot;$URL_PCONN&amp;quot;   &lt;br /&gt;
fetch_stats &amp;quot;$URL_AVG60&amp;quot;   &lt;br /&gt;
&lt;br /&gt;
FD_INFO=$(grep -A 7 &amp;quot;File descriptor usage for squid:&amp;quot; &amp;quot;${STATS_DIR}/${DATE}/${URL_INFO#mgr:}&amp;quot;)&lt;br /&gt;
add_s store_fds     $(echo &amp;quot;$FD_INFO&amp;quot; | grep &amp;quot;Store Disk files open:&amp;quot; | cut -d: -f 2 | sed -e 's/ //g')&lt;br /&gt;
add_s reserved_fds  $(echo &amp;quot;$FD_INFO&amp;quot; | grep &amp;quot;Reserved number of file descriptors:&amp;quot; | cut -d: -f 2 | sed -e 's/ //g')&lt;br /&gt;
add_s available_fds $(echo &amp;quot;$FD_INFO&amp;quot; | grep &amp;quot;Available number of file descriptors:&amp;quot; | cut -d: -f 2 | sed -e 's/ //g')&lt;br /&gt;
add_s used_fds      $(echo &amp;quot;$FD_INFO&amp;quot; | grep &amp;quot;Number of file desc currently in use:&amp;quot; | cut -d: -f 2 | sed -e 's/ //g')&lt;br /&gt;
&lt;br /&gt;
add_s socket_fds $(sed -e 's/  */ /g' -e 's/^ *//' &amp;lt; &amp;quot;${STATS_DIR}/${DATE}/${URL_FD#mgr:}&amp;quot; | egrep &amp;quot;^[[:digit:]]+ Socket&amp;quot; | wc -l)&lt;br /&gt;
&lt;br /&gt;
C_CONN_TOTAL=0&lt;br /&gt;
C_TOTAL=0&lt;br /&gt;
C_CONNECTIONS=$(grep &amp;quot;Currently established connections&amp;quot; &amp;quot;${STATS_DIR}/${DATE}/${URL_CLIENTS#mgr:}&amp;quot; | cut -d: -f 2)&lt;br /&gt;
for C_CONN in $C_CONNECTIONS&lt;br /&gt;
do &lt;br /&gt;
	if [ $C_CONN -gt 0 ]&lt;br /&gt;
	then&lt;br /&gt;
		C_TOTAL=$(( $C_TOTAL + 1 ))&lt;br /&gt;
		C_CONN_TOTAL=$(( $C_CONN_TOTAL + $C_CONN ))&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
add_s clients_connected $C_TOTAL&lt;br /&gt;
add_s client_fds $C_CONN_TOTAL&lt;br /&gt;
&lt;br /&gt;
#��The number of idle persistent connections per origin server&lt;br /&gt;
&amp;lt; &amp;quot;${STATS_DIR}/${DATE}/${URL_FD#mgr:}&amp;quot; \&lt;br /&gt;
	sed -e 1,15d -e 's/^ *//' -e 's/  */ /g' | \&lt;br /&gt;
	cut -d\  -f 2,6- | \&lt;br /&gt;
	grep &amp;quot;^Socket.*idle connection$&amp;quot; | \&lt;br /&gt;
	cut -d\  -f 3 | \&lt;br /&gt;
	sort | \&lt;br /&gt;
	uniq -c | \&lt;br /&gt;
	sort -nr | \&lt;br /&gt;
	sed -e 's/^ *//' \&lt;br /&gt;
	&amp;gt; &amp;quot;${STATS_DIR}/${DATE}/idle_origin_servers&amp;quot;&lt;br /&gt;
add_s idle_origin_servers $(wc -l &amp;quot;${STATS_DIR}/${DATE}/idle_origin_servers&amp;quot;)&lt;br /&gt;
add_s idle_origin_sockets $(&amp;lt; &amp;quot;${STATS_DIR}/${DATE}/idle_origin_servers&amp;quot; cut -d\  -f 1 | tr &amp;quot;\n&amp;quot; &amp;quot;+&amp;quot; | sed -e 's/\+$//' | bc)&lt;br /&gt;
&lt;br /&gt;
# The number of idle persistnent connections per client&lt;br /&gt;
&amp;lt; &amp;quot;${STATS_DIR}/${DATE}/${URL_FD#mgr:}&amp;quot; \&lt;br /&gt;
	sed -e 1,15d -e 's/^ *//' -e 's/  */ /g' | \&lt;br /&gt;
	cut -d\  -f 2,6- | \&lt;br /&gt;
	grep &amp;quot;^Socket.*Waiting for next request$&amp;quot; | \&lt;br /&gt;
	cut -d\  -f 2 | \&lt;br /&gt;
	cut -d. -f -4 | \&lt;br /&gt;
	sort | \&lt;br /&gt;
	uniq -c | \&lt;br /&gt;
	sort -nr | \&lt;br /&gt;
	sed -e 's/^ *//' \&lt;br /&gt;
	&amp;gt; &amp;quot;${STATS_DIR}/${DATE}/idle_clients&amp;quot;&lt;br /&gt;
add_s idle_clients $(wc -l &amp;quot;${STATS_DIR}/${DATE}/idle_clients&amp;quot;)&lt;br /&gt;
add_s idle_client_sockets $(&amp;lt; &amp;quot;${STATS_DIR}/${DATE}/idle_clients&amp;quot; cut -d\  -f 1 | tr &amp;quot;\n&amp;quot; &amp;quot;+&amp;quot; | sed -e 's/\+$//' | bc)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/SpamAssassin_Updater</id>
		<title>SpamAssassin Updater</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/SpamAssassin_Updater"/>
				<updated>2011-07-16T11:52:11Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: New page: [[Category:linux]] [[Category:bash]] [[Category:scripts]]  This script will check for new spamassassin rule sets, download them, test them, compile them and reload spamd plus keep backups ...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:linux]]&lt;br /&gt;
[[Category:bash]]&lt;br /&gt;
[[Category:scripts]]&lt;br /&gt;
&lt;br /&gt;
This script will check for new spamassassin rule sets, download them, test them, compile them and reload spamd plus keep backups of the previous verious. It make me feel a little bit better about spamassassin pulling in new rule sets automatically. Doing that is a good thing but sometimes bad rules are pushed out.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
# This script will automatically update spamassassin rules and compile them&lt;br /&gt;
# Backups are kept for at least 28 days&lt;br /&gt;
&lt;br /&gt;
###########&lt;br /&gt;
# Settings&lt;br /&gt;
&lt;br /&gt;
SA=/usr/bin/spamassassin&lt;br /&gt;
SA_UPDATE=/usr/bin/sa-update&lt;br /&gt;
SA_COMPILE=/usr/bin/sa-compile&lt;br /&gt;
SA_VAR=/var/lib/spamassassin&lt;br /&gt;
SPAMD_PID=/var/run/spamd.pid&lt;br /&gt;
BACKUP_OWNER=&amp;quot;sa-update&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
COMPILED_DIR=&amp;quot;${SA_VAR}/compiled&amp;quot;&lt;br /&gt;
BACKUP_DIR=&amp;quot;${SA_VAR}/backups&amp;quot;&lt;br /&gt;
&lt;br /&gt;
############&lt;br /&gt;
# Functions&lt;br /&gt;
&lt;br /&gt;
# date adjusts to the given number of days in the past and &lt;br /&gt;
# formatted using the provided formatting string&lt;br /&gt;
# usage: pastDate &amp;lt;minus no. days&amp;gt; &amp;lt;format&amp;gt;&lt;br /&gt;
pastDate()&lt;br /&gt;
{&lt;br /&gt;
    if [ ! $1 ]&lt;br /&gt;
    then&lt;br /&gt;
        exit 1&lt;br /&gt;
    fi&lt;br /&gt;
    if [ ! $2 ]&lt;br /&gt;
    then &lt;br /&gt;
        exit 1&lt;br /&gt;
    fi&lt;br /&gt;
    if [ `uname` = &amp;quot;Darwin&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        echo $(date -v -&amp;quot;$1&amp;quot;d +&amp;quot;$2&amp;quot;)&lt;br /&gt;
    fi&lt;br /&gt;
    if [ `uname` = &amp;quot;Linux&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        echo $(date --date=&amp;quot;$1 day ago&amp;quot; +&amp;quot;$2&amp;quot;)&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
##############&lt;br /&gt;
# For logging&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;$(date +&amp;quot;%F %X&amp;quot;) spamassassin updater&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#########################################################&lt;br /&gt;
# SpamAssassin Version and corresponding rules directory&lt;br /&gt;
&lt;br /&gt;
# spamassassin uses a different directory name to store rules, based on&lt;br /&gt;
# it's version number. The version number is converted to a &amp;quot;filesytem &lt;br /&gt;
# friendly&amp;quot; name like 3.002005 or 3.003000 for 3.2.5 and 3.3.0.&lt;br /&gt;
SA_VERSION=$(&amp;quot;${SA}&amp;quot; -V | grep SpamAssassin | sed -e 's/SpamAssassin version //')&lt;br /&gt;
SA_MAJOR=$(echo &amp;quot;${SA_VERSION}&amp;quot; | cut -d. -f 1)&lt;br /&gt;
SA_MINOR=$(echo &amp;quot;${SA_VERSION}&amp;quot; | cut -d. -f 2)&lt;br /&gt;
SA_PATCH=$(echo &amp;quot;${SA_VERSION}&amp;quot; | cut -d. -f 3)&lt;br /&gt;
RULE_DIR=&amp;quot;${SA_VAR}/$(printf &amp;quot;%d.%0#3d%0#3d&amp;quot; &amp;quot;${SA_MAJOR}&amp;quot; &amp;quot;${SA_MINOR}&amp;quot; &amp;quot;${SA_PATCH}&amp;quot;)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
###############&lt;br /&gt;
# Basic checks &lt;br /&gt;
&lt;br /&gt;
if [ ! -f &amp;quot;$SPAMD_PID&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;spamd pid file $SPAMD_PID does not exist&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ ! &amp;quot;$RULE_DIR&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;could not determine directory for spamassassin rules&amp;quot; &lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
if [ ! -d &amp;quot;$RULE_DIR&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    mkdir &amp;quot;$RULE_DIR&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
if [ ! -d &amp;quot;$RULE_DIR&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;cannot create rule directory $RULE_DIR&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$(egrep &amp;quot;^${BACKUP_OWNER}:&amp;quot; /etc/passwd | wc -l)&amp;quot; -ne 1 ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;backup owner \&amp;quot;${BACKUP_OWNER}\&amp;quot; does not exist&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ ! -d &amp;quot;$BACKUP_DIR&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    mkdir &amp;quot;$BACKUP_DIR&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
if [ ! -d &amp;quot;$BACKUP_DIR&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;cannot create backup rules directory $BACKUP_DIR&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
if [ ! -w &amp;quot;$BACKUP_DIR&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;backup rules directory $BACKUP_DIR is not writable&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
############&lt;br /&gt;
# Spamd pid &lt;br /&gt;
&lt;br /&gt;
SPAMD_PID=$(cat &amp;quot;$SPAMD_PID&amp;quot;)&lt;br /&gt;
if [ ! &amp;quot;$(ps -p &amp;quot;$SPAMD_PID&amp;quot; --no-headers)&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;spamd is not running&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
###############&lt;br /&gt;
# Backup dates&lt;br /&gt;
&lt;br /&gt;
TODAY=$(date +%F)&lt;br /&gt;
FOUR_WEEKS_AGO=$(pastDate 28 %F)&lt;br /&gt;
&lt;br /&gt;
###################################&lt;br /&gt;
# Check for availabilty of updates&lt;br /&gt;
&lt;br /&gt;
&amp;quot;$SA_UPDATE&amp;quot; --gpg --checkonly&lt;br /&gt;
SA_UPDATE_EXIT_CODE=$?&lt;br /&gt;
if [ $SA_UPDATE_EXIT_CODE -eq 1 ]&lt;br /&gt;
then &lt;br /&gt;
    echo &amp;quot;No updates available&amp;quot;&lt;br /&gt;
    exit 0&lt;br /&gt;
elif [ $SA_UPDATE_EXIT_CODE -gt 1 ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;sa-update returned error $SA_UPDATE_EXIT_CODE&amp;quot;&lt;br /&gt;
    exit $SA_UPDATE_EXIT_CODE&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
########################&lt;br /&gt;
# Backup existing rules &lt;br /&gt;
&lt;br /&gt;
mkdir &amp;quot;$BACKUP_DIR/$TODAY&amp;quot;&lt;br /&gt;
cp -rp &amp;quot;$RULE_DIR&amp;quot; &amp;quot;$BACKUP_DIR/$TODAY/&amp;quot; &lt;br /&gt;
cp -rp &amp;quot;$COMPILED_DIR&amp;quot; &amp;quot;$BACKUP_DIR/$TODAY/&amp;quot; &lt;br /&gt;
chown -R $BACKUP_OWNER &amp;quot;$BACKUP_DIR/$TODAY&amp;quot;&lt;br /&gt;
&lt;br /&gt;
###############&lt;br /&gt;
# Update rules&lt;br /&gt;
&lt;br /&gt;
&amp;quot;$SA_UPDATE&amp;quot; $GPGKEYS&lt;br /&gt;
SA_UPDATE_EXIT_CODE=$?&lt;br /&gt;
if [ $SA_UPDATE_EXIT_CODE -eq 1 ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;No updates available&amp;quot;&lt;br /&gt;
    exit 0&lt;br /&gt;
elif [ $SA_UPDATE_EXIT_CODE -gt 1 ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;sa-update returned error $SA_UPDATE_EXIT_CODE&amp;quot;&lt;br /&gt;
    exit $SA_UPDATE_EXIT_CODE&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
################&lt;br /&gt;
# Compile rules&lt;br /&gt;
&lt;br /&gt;
&amp;quot;$SA_COMPILE&amp;quot;&lt;br /&gt;
SA_COMPILE_EXIT_CODE=$?&lt;br /&gt;
if [ $SA_COMPILE_EXIT_CODE -ne 0 ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;sa-compile failed with error $SA_COMPILE_EXIT_CODE&amp;quot;&lt;br /&gt;
    exit $SA_COMPILE_EXIT_CODE&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
##########################################&lt;br /&gt;
# Reload spamassassin spamd configuration&lt;br /&gt;
&lt;br /&gt;
kill -s SIGHUP &amp;quot;$SPAMD_PID&amp;quot;&lt;br /&gt;
&lt;br /&gt;
##########################&lt;br /&gt;
# Remove old rule backups&lt;br /&gt;
&lt;br /&gt;
cd &amp;quot;$BACKUP_DIR&amp;quot;&lt;br /&gt;
for DIR in *&lt;br /&gt;
do&lt;br /&gt;
    # be paranoid and check that the directory name looks plausible&lt;br /&gt;
    if [ $(echo &amp;quot;$DIR&amp;quot; | egrep &amp;quot;^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}$&amp;quot;) ]&lt;br /&gt;
    then&lt;br /&gt;
	# strip the hyphens from the date: YYYY-MM-DD becomes YYYYMMDD, now we can do numerical comparisons&lt;br /&gt;
        if [ &amp;quot;${DIR//-/}&amp;quot; -lt &amp;quot;${FOUR_WEEKS_AGO//-/}&amp;quot; ]&lt;br /&gt;
        then&lt;br /&gt;
            sudo -u $BACKUP_OWNER rm -rf &amp;quot;${BACKUP_DIR}/${DIR}&amp;quot;&lt;br /&gt;
        fi&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Spamd_stats</id>
		<title>Spamd stats</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Spamd_stats"/>
				<updated>2011-07-16T11:47:30Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: New page: [[Category:linux]] [[Category:perl]]  This script will collect stats from the spamd logs. It's based on another script called exim-stats and has only been modified in a minor way. The scri...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:linux]]&lt;br /&gt;
[[Category:perl]]&lt;br /&gt;
&lt;br /&gt;
This script will collect stats from the spamd logs. It's based on another script called exim-stats and has only been modified in a minor way. The script will output values that can be collected by cacti. I'll leave it to you to create your own data and graph templates. I collect the data over snmp. An snmpd on the same host as the spamd, has an extend directive, that simply cats out the stats file when an certain OID is queried.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
[kieranw@nologo bin]$ cat spamd_stats.pl &lt;br /&gt;
#! /usr/bin/perl&lt;br /&gt;
#&lt;br /&gt;
# spamd stats grabber for NET-SNMP&lt;br /&gt;
#&lt;br /&gt;
# Based on exim stats grabber for NET-SNMP, which was based on a script &lt;br /&gt;
# by Matthew Newton and Copyright (c) University of Leicester, 2005&lt;br /&gt;
#&lt;br /&gt;
# Exim stats Slightly modified for Timico (http://timico.net) by &lt;br /&gt;
# Ian P. Christian. More information about Ian P. Christian's version &lt;br /&gt;
# can be found at &lt;br /&gt;
# http://pookey.co.uk/wordpress/archives/70-cacti-and-exim-a-mostly-complete-guide-part-1&lt;br /&gt;
#&lt;br /&gt;
# The spamd version of the script was made at Queen Mary College, Apr 2010&lt;br /&gt;
#&lt;br /&gt;
# This program is free software; you can redistribute it and/or&lt;br /&gt;
# modify it under the terms of the GNU General Public License as&lt;br /&gt;
# published by the Free Software Foundation; either version 2 of&lt;br /&gt;
# the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
# This program is distributed in the hope that it will be useful,&lt;br /&gt;
# but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
# GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
# You should have received a copy of the GNU General Public&lt;br /&gt;
# License along with this program; if not, write to the Free&lt;br /&gt;
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,&lt;br /&gt;
# Boston, MA 02110-1301, USA.&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Options to set up here.&lt;br /&gt;
#&lt;br /&gt;
# $conf is where to store the current state file.&lt;br /&gt;
# $statistics is the file that contains the current data.&lt;br /&gt;
# $maillog is the latest spamd main log.&lt;br /&gt;
# $mainlogold is the last rotated out main log.&lt;br /&gt;
# $archive is a directory. If it exists then old data is written&lt;br /&gt;
#          there, too.&lt;br /&gt;
&lt;br /&gt;
my $conf = &amp;quot;/var/lib/spamd/stats/conf&amp;quot;;&lt;br /&gt;
my $statsfile = &amp;quot;/var/lib/spamd/stats/statistics&amp;quot;;&lt;br /&gt;
my $mainlog = &amp;quot;/var/log/spamd&amp;quot;;&lt;br /&gt;
my $mainlogold = &amp;quot;/var/log/spamd.1.bz2&amp;quot;;&lt;br /&gt;
#my $archive = &amp;quot;/usr/local/exim-snmp-stats/archive&amp;quot;;&lt;br /&gt;
my $archive = &amp;quot;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# The regular expressions will need tweaking below, especially the&lt;br /&gt;
# IP addresses that determine local or remote. This should be&lt;br /&gt;
# moved to a configuration file some day.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# read conf file of when last run and where we got to&lt;br /&gt;
&lt;br /&gt;
my %stats = ();&lt;br /&gt;
&lt;br /&gt;
# set some defaults. If the current-state file does not exist, lets&lt;br /&gt;
# start searching through the current mainlog from the beginning.&lt;br /&gt;
# Maybe in this case we should really just set $seek to be the last&lt;br /&gt;
# position in the file so that the beginning stats are not large?&lt;br /&gt;
my $seek = 0;&lt;br /&gt;
my $inode = inode_number($mainlog);&lt;br /&gt;
my $cantseek = 0;&lt;br /&gt;
&lt;br /&gt;
if (-r $conf) {&lt;br /&gt;
  open CONF, &amp;quot;&amp;lt; $conf&amp;quot;;&lt;br /&gt;
  while (&amp;lt;CONF&amp;gt;) {&lt;br /&gt;
    chomp;&lt;br /&gt;
    s/^\s*//;&lt;br /&gt;
    s/\s*$//;&lt;br /&gt;
    next if /^$/;&lt;br /&gt;
    if (/^inode=(\d+)$/) {&lt;br /&gt;
      $inode = $1;&lt;br /&gt;
    }&lt;br /&gt;
    if (/^seek=(.*)$/) {&lt;br /&gt;
      $seek = $1;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  close CONF;&lt;br /&gt;
}&lt;br /&gt;
$stats{&amp;quot;connections&amp;quot;} = 0;&lt;br /&gt;
$stats{&amp;quot;spam&amp;quot;} = 0;&lt;br /&gt;
$stats{&amp;quot;clean&amp;quot;} = 0;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# see if we can seek to current position in the mainlog. If not, then&lt;br /&gt;
# it has most likely been rotated&lt;br /&gt;
open LOG, &amp;quot;&amp;lt; $mainlog&amp;quot; or die &amp;quot;cannot open exim log file $mainlog!&amp;quot;;&lt;br /&gt;
if (!seek(LOG, $seek, 0)) {&lt;br /&gt;
  $cantseek = 1;&lt;br /&gt;
}&lt;br /&gt;
close LOG;&lt;br /&gt;
&lt;br /&gt;
if ($inode != inode_number($mainlog) or&lt;br /&gt;
    $cantseek or&lt;br /&gt;
    $inode == inode_number($mainlogold) or&lt;br /&gt;
    $seek &amp;gt; (stat($mainlog))[7] ) {&lt;br /&gt;
  # we have changed to a new log file; read the previous mainlog first&lt;br /&gt;
  if ($mainlogold =~ /\.bz2$/) {&lt;br /&gt;
      my $oldumask = umask;&lt;br /&gt;
      umask 0077;&lt;br /&gt;
      `bunzip2 -ck $mainlogold &amp;gt; /tmp/spamd_stats.$$`;&lt;br /&gt;
      read_log(&amp;quot;/tmp/spamd_stats.$$&amp;quot;, $seek, \%stats);&lt;br /&gt;
      unlink(&amp;quot;/tmp/spamd_stats.$$&amp;quot;);&lt;br /&gt;
      umask $oldumask;&lt;br /&gt;
  } else {&lt;br /&gt;
      read_log($mainlogold, $seek, \%stats);&lt;br /&gt;
  }&lt;br /&gt;
  $inode = inode_number($mainlog);&lt;br /&gt;
  $seek = 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$seek = read_log($mainlog, $seek, \%stats);&lt;br /&gt;
&lt;br /&gt;
write_stats($statsfile, \%stats);&lt;br /&gt;
&lt;br /&gt;
# create config file&lt;br /&gt;
open CONF, &amp;quot;&amp;gt; $conf&amp;quot;;&lt;br /&gt;
print CONF &amp;quot;inode=$inode\n&amp;quot;;&lt;br /&gt;
print CONF &amp;quot;seek=$seek\n&amp;quot;;&lt;br /&gt;
close CONF;&lt;br /&gt;
&lt;br /&gt;
if (defined $archive and $archive ne &amp;quot;&amp;quot; and -d $archive) {&lt;br /&gt;
  write_stats($archive.&amp;quot;/&amp;quot;.now_time(), \%stats);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
exit;&lt;br /&gt;
&lt;br /&gt;
sub now_time&lt;br /&gt;
{&lt;br /&gt;
  my @n = gmtime();&lt;br /&gt;
  my ($y, $m, $d) = ($n[5]+1900, $n[4]+1, $n[3]);&lt;br /&gt;
  my ($hr, $mn, $sc) = ($n[2], $n[1], $n[0]);&lt;br /&gt;
  $m = &amp;quot;0$m&amp;quot; if ($m &amp;lt; 10);&lt;br /&gt;
  $d = &amp;quot;0$d&amp;quot; if ($d &amp;lt; 10);&lt;br /&gt;
  $hr = &amp;quot;0$hr&amp;quot; if ($hr &amp;lt; 10);&lt;br /&gt;
  $mn = &amp;quot;0$mn&amp;quot; if ($mn &amp;lt; 10);&lt;br /&gt;
  $sc = &amp;quot;0$sc&amp;quot; if ($sc &amp;lt; 10);&lt;br /&gt;
  return &amp;quot;$y-$m-$d-$hr-$mn-$sc&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub inode_number&lt;br /&gt;
{&lt;br /&gt;
  my $file = shift;&lt;br /&gt;
  my ($dummy, $inode) = stat($file);&lt;br /&gt;
  return $inode;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub read_log&lt;br /&gt;
{&lt;br /&gt;
  my ($file, $seek, $stats) = @_;&lt;br /&gt;
  my $prevline = undef;&lt;br /&gt;
  my $line;&lt;br /&gt;
  my ($prevpos, $pos);&lt;br /&gt;
  local *LOG;&lt;br /&gt;
&lt;br /&gt;
  open LOG, &amp;quot;&amp;lt; $file&amp;quot; or die &amp;quot;cannot open spamd log file $file!&amp;quot;;&lt;br /&gt;
  if (!seek(LOG, $seek, 0)) {&lt;br /&gt;
    close LOG;&lt;br /&gt;
    return $seek;&lt;br /&gt;
  }&lt;br /&gt;
  while ($line = &amp;lt;LOG&amp;gt;) {&lt;br /&gt;
    if (defined $prevline) {&lt;br /&gt;
      if ($line =~ /spamd: connection from/) {&lt;br /&gt;
        $$stats{&amp;quot;connections&amp;quot;}++;&lt;br /&gt;
      } elsif ($line =~ /spamd: identified spam/) {&lt;br /&gt;
        $$stats{&amp;quot;spam&amp;quot;}++;&lt;br /&gt;
      } elsif ($line =~ /spamd: clean message/) {&lt;br /&gt;
        $$stats{&amp;quot;clean&amp;quot;}++;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    $prevline = $line;&lt;br /&gt;
    $prevpos = $pos;&lt;br /&gt;
    $pos = tell LOG;&lt;br /&gt;
  }&lt;br /&gt;
  close LOG;&lt;br /&gt;
&lt;br /&gt;
  $prevpos = $seek unless defined $prevpos;&lt;br /&gt;
&lt;br /&gt;
  return $prevpos;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub write_stats&lt;br /&gt;
{&lt;br /&gt;
  my ($file, $stats) = @_;&lt;br /&gt;
  local *STATS;&lt;br /&gt;
&lt;br /&gt;
  open STATS, &amp;quot;&amp;gt; $file&amp;quot;;&lt;br /&gt;
  print STATS &amp;lt;&amp;lt;EOF;&lt;br /&gt;
$$stats{&amp;quot;connections&amp;quot;}&lt;br /&gt;
$$stats{&amp;quot;spam&amp;quot;}&lt;br /&gt;
$$stats{&amp;quot;clean&amp;quot;}&lt;br /&gt;
EOF&lt;br /&gt;
  close STATS;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Calamaris</id>
		<title>Calamaris</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Calamaris"/>
				<updated>2011-07-16T11:41:42Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: New page: [[Category:linux]] [[Category:bash]] [[Category:scripts]] [[Category:perl]]  Calamaris is a log analyser for squid. It makes nice reports that management type like. Actually they're very u...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:linux]]&lt;br /&gt;
[[Category:bash]]&lt;br /&gt;
[[Category:scripts]]&lt;br /&gt;
[[Category:perl]]&lt;br /&gt;
&lt;br /&gt;
Calamaris is a log analyser for squid. It makes nice reports that management type like. Actually they're very usful in their own right.&lt;br /&gt;
&lt;br /&gt;
This script will run calamaris over the squid access logs every night and build up a collection of Daily, Weekly and Monthly reports going back over the last two years.&lt;br /&gt;
&lt;br /&gt;
It relies on a little perl script to split the access log up in to one log file per day. Most servers rotate their logs in the early hours of the morning. I wanted the reports to represent one whole day from 00:00 hrs to 23:59 hrs&lt;br /&gt;
&lt;br /&gt;
access-log-split.pl:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/usr/bin/env perl&lt;br /&gt;
&lt;br /&gt;
# Take the squid log file specified as the first argument when calling this script, &lt;br /&gt;
# then split all entries in to seperate files for each day.&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
use File::Basename;&lt;br /&gt;
use POSIX;&lt;br /&gt;
&lt;br /&gt;
sub isoDate {&lt;br /&gt;
    return strftime(&amp;quot;%Y-%m-%d&amp;quot;, localtime(shift or time));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
my $logtype = &amp;quot;access&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
my $previousDate = '';&lt;br /&gt;
my $logfile;&lt;br /&gt;
while (&amp;lt;&amp;gt;) {&lt;br /&gt;
    my $line = $_;&lt;br /&gt;
    my $timeStamp = 0;&lt;br /&gt;
    if ($line =~ /^(\d+)\..*/) {&lt;br /&gt;
        $timeStamp = $1;&lt;br /&gt;
    }&lt;br /&gt;
    my $currentDate = isoDate($timeStamp);&lt;br /&gt;
    if ($currentDate ne $previousDate || !$logfile) {&lt;br /&gt;
        if ($logfile) {&lt;br /&gt;
            close($logfile);&lt;br /&gt;
        }&lt;br /&gt;
        open $logfile, &amp;quot;&amp;gt;&amp;gt;&amp;quot;, &amp;quot;$logtype.$currentDate&amp;quot; &lt;br /&gt;
            or die &amp;quot;Could not open $logtype.$currentDate: $!&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    print $logfile $line;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
calamaris.sh:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#&lt;br /&gt;
# A script to generate calamaris log reports from the squid access logs&lt;br /&gt;
#&lt;br /&gt;
# This script depends on the squid log rotation script, &lt;br /&gt;
# /etc/cron.daily/squid.daily.job, and must be run after it.&lt;br /&gt;
#&lt;br /&gt;
# The script creates daily, weekly and monthly reports. It also keeps &lt;br /&gt;
# the last copy of any given day, week or month to allow comaprisons.&lt;br /&gt;
#&lt;br /&gt;
# The script needs to run each day, it won't catch up if any days are&lt;br /&gt;
# missed. If that happens, weekly and monthly reports will still be&lt;br /&gt;
# created but won't be accurate.&lt;br /&gt;
#&lt;br /&gt;
# A simple perl script, &amp;quot;access-log-split.pl&amp;quot;, is used to divide log &lt;br /&gt;
# data in to one file per day, which is then boiled down by calamaris&lt;br /&gt;
# in to daily cache files. These cache files are kept for one month. &lt;br /&gt;
&lt;br /&gt;
################&lt;br /&gt;
# Configuration&lt;br /&gt;
&lt;br /&gt;
CALAMARIS=/usr/local/calamaris/calamaris&lt;br /&gt;
CONF=/usr/local/calamaris/calamaris.conf&lt;br /&gt;
&lt;br /&gt;
# Logs are picked up from the log archive directory. See /etc/cron.daily/squid.daily.job&lt;br /&gt;
LOG_DIR=/var/log/squid&lt;br /&gt;
ACCESS_LOG=&amp;quot;${LOG_DIR}/access.log&amp;quot;&lt;br /&gt;
&lt;br /&gt;
CACHE_HOSTNAME=squid-cache.example.com&lt;br /&gt;
&lt;br /&gt;
CURRENT_REPORTS_DIR=/var/lib/calamaris/reports&lt;br /&gt;
PREVIOUS_REPORTS_DIR=&amp;quot;${CURRENT_REPORTS_DIR}/previous&amp;quot;&lt;br /&gt;
&lt;br /&gt;
CACHE=/var/lib/calamaris/cache&lt;br /&gt;
&lt;br /&gt;
BZCAT=`which bzcat`&lt;br /&gt;
CAT=`which cat`&lt;br /&gt;
LOGSPLIT=/usr/local/bin/access-log-split.pl&lt;br /&gt;
RSYNC=`which rsync`&lt;br /&gt;
&lt;br /&gt;
REMOTE_HOST=www.example.com&lt;br /&gt;
REMOTE_USER=calamari&lt;br /&gt;
REMOTE_PATH=/var/www/html/squid-reports&lt;br /&gt;
REMOTE_SHELL=&amp;quot;ssh -q -i /var/ib/calamaris/.ssh/id_rsa -o UserKnownHostsFile=/var/lib/calamaris/.ssh/known_hosts&amp;quot;&lt;br /&gt;
&lt;br /&gt;
NICENESS=39&lt;br /&gt;
&lt;br /&gt;
DAILY_REPORT_LABEL=daily&lt;br /&gt;
WEEKLY_REPORT_LABEL=weekly&lt;br /&gt;
MONTHLY_REPORT_LABEL=monthly&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
########################&lt;br /&gt;
# Options for calamaris&lt;br /&gt;
&lt;br /&gt;
DEFAULT_ARGUMENTS=&amp;quot;&lt;br /&gt;
--errorcode-distribution-report \&lt;br /&gt;
--input-format squid-extended \&lt;br /&gt;
--hostname ${CACHE_HOSTNAME} \&lt;br /&gt;
--peak-report new \&lt;br /&gt;
--response-time-report \&lt;br /&gt;
--size-distribution-report 10 \&lt;br /&gt;
--status-report \&lt;br /&gt;
--type-report-ignore-case&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# When generating cache files, keep don't limit the lenght of reports&lt;br /&gt;
CACHE_ARGUMENTS=&amp;quot;${DEFAULT_ARGUMENTS} \&lt;br /&gt;
--benchmark 50000 \&lt;br /&gt;
--domain-report -1 \&lt;br /&gt;
--performance-report 60 \&lt;br /&gt;
--requester-report -1 \&lt;br /&gt;
--type-report -1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Limit the length of reports for general consumption - to limit &lt;br /&gt;
# privacy issues&lt;br /&gt;
OUTPUT_ARGUMENTS=&amp;quot;${DEFAULT_ARGUMENTS} \&lt;br /&gt;
--benchmark 10000 \&lt;br /&gt;
--domain-report 50 \&lt;br /&gt;
--requester-report 50 \&lt;br /&gt;
--type-report 50 \&lt;br /&gt;
--output-format html,graph \&lt;br /&gt;
--image-type gif&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
############&lt;br /&gt;
# functions&lt;br /&gt;
&lt;br /&gt;
# date adjusts to the given number of days in the past and &lt;br /&gt;
# formatted using the provided formatting string&lt;br /&gt;
# usage: pastDate &amp;lt;minus no. days&amp;gt; &amp;lt;format&amp;gt;&lt;br /&gt;
pastDate()&lt;br /&gt;
{&lt;br /&gt;
    if [ ! $1 ]&lt;br /&gt;
    then&lt;br /&gt;
        exit 1&lt;br /&gt;
    fi&lt;br /&gt;
    if [ ! $2 ]&lt;br /&gt;
    then &lt;br /&gt;
        exit 1&lt;br /&gt;
    fi&lt;br /&gt;
    if [ `uname` = &amp;quot;Darwin&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        echo $(date -v -&amp;quot;$1&amp;quot;d +&amp;quot;$2&amp;quot;)&lt;br /&gt;
    fi&lt;br /&gt;
    if [ `uname` = &amp;quot;Linux&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        echo $(date --date=&amp;quot;$1 day ago&amp;quot; +&amp;quot;$2&amp;quot;)&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
##############################&lt;br /&gt;
# Directory Checks / Creation&lt;br /&gt;
&lt;br /&gt;
# Check required directories are writable - try to create them if missing or&lt;br /&gt;
# exit.&lt;br /&gt;
test -e &amp;quot;${CACHE}&amp;quot; || test -d &amp;quot;${CACHE}&amp;quot; || mkdir &amp;quot;${CACHE}&amp;quot;&lt;br /&gt;
if [ ! -d &amp;quot;${CACHE}&amp;quot; -o ! -w &amp;quot;${CACHE}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;The cache directory, &amp;quot;&lt;br /&gt;
    echo &amp;quot;'${CACHE}',&amp;quot;&lt;br /&gt;
    echo &amp;quot;does not exist or is not writable&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ ! -d &amp;quot;${CURRENT_REPORTS_DIR}&amp;quot; -o ! -w &amp;quot;${CURRENT_REPORTS_DIR}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;The reports directory, &amp;quot;&lt;br /&gt;
    echo &amp;quot;'${CURRENT_REPORTS_DIR}',&amp;quot;&lt;br /&gt;
    echo &amp;quot;does not exist or is not writable&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
DAILY_DIR=&amp;quot;${CURRENT_REPORTS_DIR}/${DAILY_REPORT_LABEL}&amp;quot;&lt;br /&gt;
test -e &amp;quot;${DAILY_DIR}&amp;quot; || test -d &amp;quot;${DAILY_DIR}&amp;quot; || mkdir &amp;quot;${DAILY_DIR}&amp;quot;&lt;br /&gt;
if [ ! -d &amp;quot;${DAILY_DIR}&amp;quot; -o ! -w &amp;quot;${DAILY_DIR}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;The daily reports directory, &amp;quot;&lt;br /&gt;
    echo &amp;quot;'${DAILY_DIR}',&amp;quot;&lt;br /&gt;
    echo &amp;quot; does not exist or is not writable&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
WEEKLY_DIR=&amp;quot;${CURRENT_REPORTS_DIR}/${WEEKLY_REPORT_LABEL}&amp;quot;&lt;br /&gt;
test -e &amp;quot;${WEEKLY_DIR}&amp;quot; || test -d &amp;quot;${WEEKLY_DIR}&amp;quot; || mkdir &amp;quot;${WEEKLY_DIR}&amp;quot;&lt;br /&gt;
if [ ! -d &amp;quot;${WEEKLY_DIR}&amp;quot; -o ! -w &amp;quot;${WEEKLY_DIR}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;The monthly reports directory, &amp;quot;&lt;br /&gt;
    echo &amp;quot;'${WEEKLY_DIR}',&amp;quot;&lt;br /&gt;
    echo &amp;quot; does not exist or is not writable&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
MONTHLY_DIR=&amp;quot;${CURRENT_REPORTS_DIR}/${MONTHLY_REPORT_LABEL}&amp;quot;&lt;br /&gt;
test -e &amp;quot;${MONTHLY_DIR}&amp;quot; || test -d &amp;quot;${MONTHLY_DIR}&amp;quot; || mkdir &amp;quot;${MONTHLY_DIR}&amp;quot;&lt;br /&gt;
if [ ! -d &amp;quot;${MONTHLY_DIR}&amp;quot; -o ! -w &amp;quot;${MONTHLY_DIR}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;The monthly reports directory, &amp;quot;&lt;br /&gt;
    echo &amp;quot;'${MONTHLY_DIR}',&amp;quot;&lt;br /&gt;
    echo &amp;quot; does not exist or is not writable&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ ! -d &amp;quot;${PREVIOUS_REPORTS_DIR}&amp;quot; -o ! -w &amp;quot;${PREVIOUS_REPORTS_DIR}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;The previous reports directory, &amp;quot;&lt;br /&gt;
    echo &amp;quot;'${PREVIOUS_REPORTS_DIR}',&amp;quot;&lt;br /&gt;
    echo &amp;quot;does not exist or is not writable&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
PREV_DAILY_DIR=&amp;quot;${PREVIOUS_REPORTS_DIR}/${DAILY_REPORT_LABEL}&amp;quot;&lt;br /&gt;
test -e &amp;quot;${PREV_DAILY_DIR}&amp;quot; || test -d &amp;quot;${PREV_DAILY_DIR}&amp;quot; || mkdir &amp;quot;${PREV_DAILY_DIR}&amp;quot;&lt;br /&gt;
if [ ! -d &amp;quot;${PREV_DAILY_DIR}&amp;quot; -o ! -w &amp;quot;${PREV_DAILY_DIR}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;The daily reports directory, &amp;quot;&lt;br /&gt;
    echo &amp;quot;'${PREV_DAILY_DIR}',&amp;quot;&lt;br /&gt;
    echo &amp;quot; does not exist or is not writable&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
PREV_WEEKLY_DIR=&amp;quot;${PREVIOUS_REPORTS_DIR}/${WEEKLY_REPORT_LABEL}&amp;quot;&lt;br /&gt;
test -e &amp;quot;${PREV_WEEKLY_DIR}&amp;quot; || test -d &amp;quot;${PREV_WEEKLY_DIR}&amp;quot; || mkdir &amp;quot;${PREV_WEEKLY_DIR}&amp;quot;&lt;br /&gt;
if [ ! -d &amp;quot;${PREV_WEEKLY_DIR}&amp;quot; -o ! -w &amp;quot;${PREV_WEEKLY_DIR}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;The monthly reports directory, &amp;quot;&lt;br /&gt;
    echo &amp;quot;'${PREV_WEEKLY_DIR}',&amp;quot;&lt;br /&gt;
    echo &amp;quot; does not exist or is not writable&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
PREV_MONTHLY_DIR=&amp;quot;${PREVIOUS_REPORTS_DIR}/${MONTHLY_REPORT_LABEL}&amp;quot;&lt;br /&gt;
test -e &amp;quot;${PREV_MONTHLY_DIR}&amp;quot; || test -d &amp;quot;${PREV_MONTHLY_DIR}&amp;quot; || mkdir &amp;quot;${PREV_MONTHLY_DIR}&amp;quot;&lt;br /&gt;
if [ ! -d &amp;quot;${PREV_MONTHLY_DIR}&amp;quot; -o ! -w &amp;quot;${PREV_MONTHLY_DIR}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;The monthly reports directory, &amp;quot;&lt;br /&gt;
    echo &amp;quot;'${PREV_MONTHLY_DIR}',&amp;quot;&lt;br /&gt;
    echo &amp;quot; does not exist or is not writable&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
########&lt;br /&gt;
# Dates&lt;br /&gt;
&lt;br /&gt;
# these dates relate to the log files, i.e. yesterdays logs and activity.&lt;br /&gt;
DAY_OF_WEEK=$(pastDate 1 %w)&lt;br /&gt;
WEEK=$(pastDate 1 %U)&lt;br /&gt;
MONTH=$(pastDate 1 %m)&lt;br /&gt;
YEAR=$(pastDate 1 %Y)&lt;br /&gt;
DATE=$(pastDate 1 %F)&lt;br /&gt;
PREV_DATE=&amp;quot;$(($YEAR - 1))${DATE:(-6)}&amp;quot;&lt;br /&gt;
PREV_PREV_DATE=&amp;quot;$(($YEAR - 2))${DATE:(-6)}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# if today is the 1st of the month, then yesterday was the end of the month&lt;br /&gt;
MONTH_ENDED=$(&lt;br /&gt;
    test $(date +%d) = 01 &amp;amp;&amp;amp; echo true&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#############################&lt;br /&gt;
# Process and Cache Log Data &lt;br /&gt;
&lt;br /&gt;
cd &amp;quot;${CACHE}&amp;quot;&lt;br /&gt;
if [ -f &amp;quot;${ACCESS_LOG}.${DAY_OF_WEEK}.bz2&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    $BZCAT &amp;quot;${ACCESS_LOG}.${DAY_OF_WEEK}.bz2&amp;quot; | $LOGSPLIT&lt;br /&gt;
    echo &amp;quot;Generating daily cache file&amp;quot;&lt;br /&gt;
    $CAT &amp;quot;${CACHE}/access.${DATE}&amp;quot; | \&lt;br /&gt;
    	nice -n ${NICENESS} &amp;quot;${CALAMARIS}&amp;quot; \&lt;br /&gt;
    	${CACHE_ARGUMENTS} \&lt;br /&gt;
    	--cache-output-file &amp;quot;${CACHE}/cache.${DATE}&amp;quot; &amp;gt; /dev/null&lt;br /&gt;
    rm &amp;quot;${CACHE}/access.${DATE}&amp;quot;&lt;br /&gt;
    echo&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;WARNING: No cache found for ${DATE}&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
###########################&lt;br /&gt;
# Create Daily HTML Report&lt;br /&gt;
&lt;br /&gt;
if [ -d &amp;quot;${DAILY_DIR}/${PREV_DATE}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;Moving previous Daily HTML report&amp;quot;&lt;br /&gt;
    [ -d &amp;quot;${PREV_DAILY_DIR}/${PREV_PREV_DATE}&amp;quot; ] &amp;amp;&amp;amp; rm -rf &amp;quot;${PREV_DAILY_DIR}/${PREV_PREV_DATE}&amp;quot;&lt;br /&gt;
    mv &amp;quot;${DAILY_DIR}/${PREV_DATE}&amp;quot; &amp;quot;${PREV_DAILY_DIR}/${PREV_DATE}&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Creating Daily HTML Report&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [ -f &amp;quot;${CACHE}/cache.${DATE}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    mkdir -p &amp;quot;${DAILY_DIR}/${DATE}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    # Get data from the cache file for the most recent day&lt;br /&gt;
    nice -n ${NICENESS} &amp;quot;${CALAMARIS}&amp;quot; \&lt;br /&gt;
        ${OUTPUT_ARGUMENTS} \&lt;br /&gt;
        --no-input \&lt;br /&gt;
        --performance-report 60 \&lt;br /&gt;
        --cache-input-file &amp;quot;${CACHE}/cache.${DATE}&amp;quot; \&lt;br /&gt;
        --output-path &amp;quot;${DAILY_DIR}/${DATE}&amp;quot;&lt;br /&gt;
    echo&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;WARNING: No cache found for ${DATE}&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#######################&lt;br /&gt;
# Create Weekly Report&lt;br /&gt;
&lt;br /&gt;
if [ $DAY_OF_WEEK -eq 6 ]&lt;br /&gt;
then&lt;br /&gt;
&lt;br /&gt;
    if [ -d &amp;quot;${WEEKLY_DIR}/${WEEK}&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        echo &amp;quot;Moving previous Weekly HTML report&amp;quot;&lt;br /&gt;
        if [ -d &amp;quot;${PREV_WEEKLY_DIR}/${WEEK}&amp;quot; ]&lt;br /&gt;
        then &lt;br /&gt;
            rm -rf &amp;quot;${PREV_WEEKLY_DIR}/${WEEK}&amp;quot;&lt;br /&gt;
        fi&lt;br /&gt;
        mv &amp;quot;${WEEKLY_DIR}/${WEEK}&amp;quot; &amp;quot;${PREV_WEEKLY_DIR}/${WEEK}&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    echo &amp;quot;Creating Weekly HTML Report&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    CACHE_FILES=&lt;br /&gt;
    DATE_ADJUSTMENT=$(( $DAY_OF_WEEK + 1 ))&lt;br /&gt;
    while [ $DATE_ADJUSTMENT -ge 1 ]&lt;br /&gt;
    do&lt;br /&gt;
        &lt;br /&gt;
        CACHE_DATE=$(pastDate $DATE_ADJUSTMENT %F)&lt;br /&gt;
        &lt;br /&gt;
        if [ -f &amp;quot;${CACHE}/cache.${CACHE_DATE}&amp;quot; ]&lt;br /&gt;
        then&lt;br /&gt;
            if [ $CACHE_FILES ]&lt;br /&gt;
            then&lt;br /&gt;
                CACHE_FILES=&amp;quot;${CACHE_FILES}:&amp;quot;&lt;br /&gt;
            fi&lt;br /&gt;
&lt;br /&gt;
            CACHE_FILES=&amp;quot;${CACHE_FILES}${CACHE}/cache.${CACHE_DATE}&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
            echo &amp;quot;WARNING: No cache found for ${CACHE_DATE}&amp;quot;&lt;br /&gt;
            continue&lt;br /&gt;
        fi&lt;br /&gt;
        &lt;br /&gt;
        DATE_ADJUSTMENT=$(( $DATE_ADJUSTMENT - 1 ))&lt;br /&gt;
        &lt;br /&gt;
    done&lt;br /&gt;
    if [ $CACHE_FILES ]&lt;br /&gt;
    then&lt;br /&gt;
        mkdir -p &amp;quot;${WEEKLY_DIR}/${WEEK}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        nice -n ${NICENESS} &amp;quot;${CALAMARIS}&amp;quot; \&lt;br /&gt;
    	    ${OUTPUT_ARGUMENTS} \&lt;br /&gt;
        	--no-input \&lt;br /&gt;
        	--cache-input-file &amp;quot;${CACHE_FILES}&amp;quot; \&lt;br /&gt;
        	--output-path &amp;quot;${WEEKLY_DIR}/${WEEK}&amp;quot;&lt;br /&gt;
        echo&lt;br /&gt;
    fi    &lt;br /&gt;
    &lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
########################&lt;br /&gt;
# Create Monthly Report&lt;br /&gt;
&lt;br /&gt;
if [ $MONTH_ENDED ]&lt;br /&gt;
then&lt;br /&gt;
&lt;br /&gt;
    if [ -d &amp;quot;${MONTHLY_DIR}/${MONTH}&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        echo &amp;quot;Moving previous Monthly HTML report&amp;quot;&lt;br /&gt;
        if [ -d &amp;quot;${PREV_MONTHLY_DIR}/${MONTH}&amp;quot; ]&lt;br /&gt;
        then &lt;br /&gt;
            rm -rf &amp;quot;${PREV_MONTHLY_DIR}/${MONTH}&amp;quot;&lt;br /&gt;
        fi&lt;br /&gt;
        mv &amp;quot;${MONTHLY_DIR}/${MONTH}&amp;quot; &amp;quot;${PREV_MONTHLY_DIR}/${MONTH}&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    echo &amp;quot;Creating Monthly HTML Report&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    CACHE_FILES=&lt;br /&gt;
    for CACHE_FILE in $(ls &amp;quot;${CACHE}&amp;quot;/cache.${YEAR}-${MONTH}-*)&lt;br /&gt;
    do&lt;br /&gt;
                &lt;br /&gt;
        if [ $CACHE_FILES ]&lt;br /&gt;
        then&lt;br /&gt;
            CACHE_FILES=&amp;quot;${CACHE_FILES}:&amp;quot;&lt;br /&gt;
        fi&lt;br /&gt;
        &lt;br /&gt;
        CACHE_FILES=&amp;quot;${CACHE_FILES}${CACHE_FILE}&amp;quot;&lt;br /&gt;
        &lt;br /&gt;
    done&lt;br /&gt;
    &lt;br /&gt;
    if [ $CACHE_FILES ]&lt;br /&gt;
    then&lt;br /&gt;
        &lt;br /&gt;
        mkdir -p &amp;quot;${MONTHLY_DIR}/${MONTH}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        nice -n ${NICENESS} &amp;quot;${CALAMARIS}&amp;quot; \&lt;br /&gt;
            ${OUTPUT_ARGUMENTS} \&lt;br /&gt;
            --no-input \&lt;br /&gt;
        	--cache-input-file &amp;quot;${CACHE_FILES}&amp;quot; \&lt;br /&gt;
        	--output-path &amp;quot;${MONTHLY_DIR}/${MONTH}&amp;quot;&lt;br /&gt;
        echo&lt;br /&gt;
        &lt;br /&gt;
    fi&lt;br /&gt;
    &lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#########################&lt;br /&gt;
# Delete old cache files&lt;br /&gt;
&lt;br /&gt;
if [ $MONTH_ENDED ]&lt;br /&gt;
then&lt;br /&gt;
&lt;br /&gt;
    echo &amp;quot;Removing old cache files&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    cd &amp;quot;${CACHE}&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    if [ ${MONTH##0} -gt 1 ]&lt;br /&gt;
    then&lt;br /&gt;
        RM_MONTH=$(printf &amp;quot;%0#2d&amp;quot; $((${MONTH##0} - 1)) )&lt;br /&gt;
        RM_YEAR=$YEAR&lt;br /&gt;
    else&lt;br /&gt;
        RM_MONTH=12&lt;br /&gt;
        RM_YEAR=$(($YEAR - 1))&lt;br /&gt;
    fi&lt;br /&gt;
    &lt;br /&gt;
    for CACHE_FILE in $(ls &amp;quot;${CACHE}&amp;quot;/cache.${RM_YEAR}-${RM_MONTH}-*)&lt;br /&gt;
    do&lt;br /&gt;
        rm &amp;quot;${CACHE}/${CACHE_FILE}&amp;quot;&lt;br /&gt;
    done&lt;br /&gt;
    &lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
###########################&lt;br /&gt;
# Copy files to web server &lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Copying files to ${REMOTE_HOST}&amp;quot;&lt;br /&gt;
nice -n ${NICENESS} $RSYNC \&lt;br /&gt;
    --chmod=D=rx --chmod=F=r --chmod=u+w \&lt;br /&gt;
    --delete-after \&lt;br /&gt;
    --recursive \&lt;br /&gt;
    --rsh=&amp;quot;${REMOTE_SHELL}&amp;quot; \&lt;br /&gt;
    --times \&lt;br /&gt;
    &amp;quot;${CURRENT_REPORTS_DIR/%\/}/&amp;quot; \&lt;br /&gt;
    &amp;quot;${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_PATH/%\/}/&amp;quot; &lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/SpamAssassin-scripts</id>
		<title>SpamAssassin-scripts</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/SpamAssassin-scripts"/>
				<updated>2011-07-16T11:31:55Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: New page: [[Category:linux]] [[Category:bash]] [[Category:scripts]]  Some simple scripts I user for working with spamassassin. See also [[Clean_Spam]] and [[Test_Spam]].  sa-deploy.sh - sanity check...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:linux]]&lt;br /&gt;
[[Category:bash]]&lt;br /&gt;
[[Category:scripts]]&lt;br /&gt;
&lt;br /&gt;
Some simple scripts I user for working with spamassassin. See also [[Clean_Spam]] and [[Test_Spam]].&lt;br /&gt;
&lt;br /&gt;
sa-deploy.sh - sanity check, compile rules, then reload rules:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
sudo spamassassin --lint &amp;amp;&amp;amp; sudo sa-compile &amp;amp;&amp;amp; sudo kill -HUP $(cat /var/run/spamd.pid)&lt;br /&gt;
exit $?&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
sa-reload.sh - sanity check and reload rules:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
sudo spamassassin --lint &amp;amp;&amp;amp; sudo kill -HUP $(cat /var/run/spamd.pid)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
sa-scantime.sh - pipe your spamd log output in to this. Yes you need that for loop if you want to filter the text stream before getting the message scan times:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
while read line; do&lt;br /&gt;
	echo $line&lt;br /&gt;
done | grep scantime | sed -e 's/Mar 21 \([^ ]*\) .*scantime=\([0-9]*\.[0-9]*\),size=\([0-9]*\).*/\1 time=\2, size=\3/g'&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
sa-sts.sh -  score, scan time  and message size for everythig that's been scanned recently:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# spamassassin score, time, size&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;time&amp;gt;\t&amp;lt;score&amp;gt;\t&amp;lt;scan time&amp;gt;\t&amp;lt;size&amp;gt;&lt;br /&gt;
&lt;br /&gt;
sudo tail -fn10000000 /var/log/spamd | \&lt;br /&gt;
	egrep 'spamd: identified spam \([1-9]?[0-9]?[0-9]' | \&lt;br /&gt;
	sed -e 's/  */ /' | \&lt;br /&gt;
	cut -d\  -f 3,5,9,13,15- | \&lt;br /&gt;
	sed -e 's/spamd\[//;&lt;br /&gt;
		s/\]://;&lt;br /&gt;
		s/(//;s/\/5.0)//;&lt;br /&gt;
		s/ bytes\.//;'       | \&lt;br /&gt;
	cut -d\  -f 1,3- | \&lt;br /&gt;
	tr &amp;quot; &amp;quot; &amp;quot;\t&amp;quot;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
sa-mem-calc.sh - see how much memory all you spamd processes are using:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
echo $(ps axo cmd,sz | grep ^spamd | sed -e 's/  */ /g' | cut -d\  -f 3 ) | sed -e 's/ /+/g' | bc&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Ldap-scripts</id>
		<title>Ldap-scripts</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Ldap-scripts"/>
				<updated>2011-07-16T11:21:01Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:linux]]&lt;br /&gt;
[[Category:bash]]&lt;br /&gt;
[[Category:scripts]]&lt;br /&gt;
&lt;br /&gt;
These are some little scripts I use to simplify working with an ldap server.&lt;br /&gt;
&lt;br /&gt;
ldap-user.sh - for simple searches, one value against one attribute:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash -x&lt;br /&gt;
&lt;br /&gt;
ldapsearch -LLL -W -Hldap://dir.example.com -D&amp;quot;cn=bossman,dc=example,dc=com&amp;quot; -x -b&amp;quot;dc=example,dc=com&amp;quot; \&lt;br /&gt;
   &amp;quot;(&amp;amp;(|(objectclass=inetorgperson)(objectClass=posixAccount))($1=$2))&amp;quot; $3&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ldap-group.sh - for simple searches, one value against one attribute:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash -x&lt;br /&gt;
&lt;br /&gt;
ldapsearch -LLL -W -Hldap://dir.example.com -D&amp;quot;cn=bossman,dc=example,dc=com&amp;quot; -x -b&amp;quot;dc=example,dc=com&amp;quot; \&lt;br /&gt;
   &amp;quot;(&amp;amp;(objectClass=posixGroup)($1=$2))&amp;quot; $3&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ldap-modify - quickly apply ldif:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash -x&lt;br /&gt;
&lt;br /&gt;
ldapmodify -P 3 -f $1 -W -Hldap://dir.example.com -D&amp;quot;cn=bossman,dc=example,dc=com&amp;quot; -x&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
user-list-to-filter.sh - simple script to convert a list of space separated user names in to an ldap filter:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
echo &amp;quot;(uid=$(echo $@| sed -e 's/ /)(uid=/g'))&amp;quot;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Test_Spam</id>
		<title>Test Spam</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Test_Spam"/>
				<updated>2011-07-16T11:15:34Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: New page: [[Category:linux]] [[Category:bash]] [[Category:scripts]]  This is a script I use for testing new spam rules. You can throw you spam corpus at spamd and see how it scores the messages.  It...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:linux]]&lt;br /&gt;
[[Category:bash]]&lt;br /&gt;
[[Category:scripts]]&lt;br /&gt;
&lt;br /&gt;
This is a script I use for testing new spam rules. You can throw you spam corpus at spamd and see how it scores the messages.&lt;br /&gt;
&lt;br /&gt;
It expexts that you will have an environment variable call $spamd set, which is the ip address or hostname of the spamd server who's rules you want to test.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;$ ./test-spam.sh ../blah/test-spam/*.eml&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
[ -z &amp;quot;$spamd&amp;quot; ] &amp;amp;&amp;amp; echo please set spamd enviroment variable to the ip/name of the spamd to use &amp;amp;&amp;amp; exit 1&lt;br /&gt;
&lt;br /&gt;
for mail in $@&lt;br /&gt;
do &lt;br /&gt;
    echo -e &amp;quot;\n$mail\n&amp;quot;&lt;br /&gt;
    spamc -d $spamd -R &amp;lt; $mail&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Clean_Spam</id>
		<title>Clean Spam</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Clean_Spam"/>
				<updated>2011-07-16T11:12:10Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: New page: [[Category:Linux]] [[Category:bash]] [[Category:scripts]]  This is a simple little script for cleaning up spam. Get the message cleaned up so it looks like it's just come in on a mailrelay...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Linux]]&lt;br /&gt;
[[Category:bash]]&lt;br /&gt;
[[Category:scripts]]&lt;br /&gt;
&lt;br /&gt;
This is a simple little script for cleaning up spam. Get the message cleaned up so it looks like it's just come in on a mailrelay, then pass it to spamassassin so you can test your new rules.&lt;br /&gt;
&lt;br /&gt;
ssed is used here, because I usually run this script on a mac. macs have bsd sed, not gnu sed and bsd sed is not all that super.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ssed -i -e '/^X-Mozilla-Status/d;&lt;br /&gt;
            /^X-SpamAssassin-Score/d;&lt;br /&gt;
            /^X-SpamAssassin-SpamBar/d;&lt;br /&gt;
            /^X-QM-SPAM-Warning/d;&lt;br /&gt;
            /^X-Sieve/d' \&lt;br /&gt;
        -e '/^Received: from mail[12]\.qmul\.ac\.uk .*/,+3d;&lt;br /&gt;
            /^X-SpamAssassin-Report/,+3d;/^ \* /d;' \&lt;br /&gt;
            $*&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Ts.sh</id>
		<title>Ts.sh</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Ts.sh"/>
				<updated>2011-03-12T11:38:57Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Bash]]&lt;br /&gt;
[[Category:Squid]]&lt;br /&gt;
&lt;br /&gt;
a simple script for getting a human readable date from a timestamp. I use this to convert the timestamps in the squid logfile.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
date -d &amp;quot;1970-01-01 $1 sec GMT&amp;quot;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	<entry>
		<id>http://wiki.ninjafocus.net/Bacula</id>
		<title>Bacula</title>
		<link rel="alternate" type="text/html" href="http://wiki.ninjafocus.net/Bacula"/>
				<updated>2011-03-12T11:24:40Z</updated>
		
		<summary type="html">&lt;p&gt;Summary: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:linux]]&lt;br /&gt;
[[Category:bash]&lt;br /&gt;
[[Category:scripts]]&lt;br /&gt;
&lt;br /&gt;
Nice backup system for linux [http://www.bacula.org http://www.bacula.org]&lt;br /&gt;
&lt;br /&gt;
Here are some functions I use to check common things in bacula&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
[kieranw@hammond ~]$ typeset -f&lt;br /&gt;
berroredvols () &lt;br /&gt;
{ &lt;br /&gt;
    echo &amp;quot;list volumes&amp;quot; | sudo /usr/sbin/bconsole | grep Error&lt;br /&gt;
}&lt;br /&gt;
bjobsrunning () &lt;br /&gt;
{ &lt;br /&gt;
    bstatusdir | grep &amp;quot;^[0-9]\{6\} [^ ]&amp;quot; | grep -E -v &amp;quot;(waiting execution|canceled|max Storage)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
bstatusclient () &lt;br /&gt;
{ &lt;br /&gt;
    echo &amp;quot;status client=$1&amp;quot; | sudo /usr/sbin/bconsole&lt;br /&gt;
}&lt;br /&gt;
bstatusdir () &lt;br /&gt;
{ &lt;br /&gt;
    echo &amp;quot;status dir&amp;quot; | sudo /usr/sbin/bconsole&lt;br /&gt;
}&lt;br /&gt;
bstatusstore () &lt;br /&gt;
{ &lt;br /&gt;
    echo status storage=tapeworm | sudo /usr/sbin/bconsole&lt;br /&gt;
}&lt;br /&gt;
btapes () &lt;br /&gt;
{ &lt;br /&gt;
    echo -e &amp;quot;query\n17\nquery\n18&amp;quot; | sudo /usr/sbin/bconsole | grep &amp;quot;^[+\|]&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
bupdateslots () &lt;br /&gt;
{ &lt;br /&gt;
    echo -e &amp;quot;update slots storage=tapeworm\n1&amp;quot; | sudo /usr/sbin/bconsole&lt;br /&gt;
}&lt;br /&gt;
bvolumes () &lt;br /&gt;
{ &lt;br /&gt;
    echo &amp;quot;list volumes&amp;quot; | sudo /usr/sbin/bconsole | grep &amp;quot;1 | LTO3&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kieran.whitbread</name></author>	</entry>

	</feed>
