Archive | May, 2006

Find/Locate size of files

17 May

We were trying to find the size of all Outlook 'pst' files on a machine.

 Can use: 

find /home -name *.pst  -exec du {\} \; | awk '{ s+= $1 } END {print "sum is: ",s}'

 OR:

locate *.pst | sed 's/ /\\ /g' | xargs ls -s | awk '{sum += $1} END { print "sum is: ", sum }' 

Port Redirect

16 May

You can't bind a privileged port (<1024).

But sometimes you need to, use Iptables to redirect or Rinetd the Internet Redirection Server – http://www.boutell.com/rinetd/

 

IMAPS Server

9 May

Q: How to have an imaps server ?

R.
a) Install one

b) or use stunnel :
   Assuming there is an imap (143) server on localhost
        stunnel  -d 993 -r 143 -f

c) or use stunnel on inetd
   imaps stream  tcp nowait cyrus /usr/sbin/stunnel -s cyrus -p /etc/ssl/certs/imapd.pem -r localhost:imap2

Can’t find file: *.MYI (errno: 2)

9 May

If you get:  Can't find file: 'myTable.MYI' (errno: 2)

It means MYI file is missing – this is okay, it can be rebuilt.

try to run (in mysql):
repair table myTable;

if you get the same error as above, run it as:
repair table myTable USE_FRM;

this should rebuild MYI  (which is an index file).

You'll have to make sure the MYD file is okay and in /var/lib/mysql/<database>

Awk – print lines which have a certain field matchin

5 May

#prints all lines that have field 1 matching field 2

$> cat <file> | awk '$1 ==$2'

 

 

# prints all lines that have 'robert' as field 4

$> awk '$4 == "robert"' <filename> 

Dates in java

5 May

If you want to print out a date: 

        SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yy hh:mm");
        Date date = new Date(timestamp);
        String formattedDate = sdf.format(date);

Where 'timestamp' is in seconds since epoch 

Dspam

5 May

My database got too big and I wanted to make it run faster.

I added some indexes to the dspam database, in <dspam-src>/src/tools.mysql_drv/mysql_objects-speed.sql:

> alter table dspam_token_data add index(spam_hits);

>alter table dspam_token_data add index(innocent_hits);

>alter table dspam_token_data add index(last_hit);

 

I then dropped my current database (probably not the best idea, but adding indexes on the fly was very very slow). And reloaded the new schema *as well as* the 'virtual_users.sql' – you will need this *or* 'virtual_user_aliases.sql'.

 To test it I used:

>echo "asdf " | /usr/local/bin/dspam –stdout –deliver=spam,innocent –mode=tum –feature=chained,noise –enable-signature-headers –user amavis

 This should return some sort of stat on the innocence of the mail. If it throws an error you might have loaded in the wrong user sql ('virtual_users.sql'/'virtual_user_aliases.sql') above, just drop the table and load in the other one.

 Finally, check 'dspam/bin/dspam_stats -H' this should have some out put on how much spam is going through the server, if this doesn't work you probably have misconfigured something. You can also check the token data in the mysql db.