dovecot: cleaning old Spam and Trash messages after some days

This script is useful to delete old messages in “Junk” mail folders (Spam, Trash) automatically after some days. adapted from these notes to work on debian/postfixadmin/dovecot #!/bin/bash # # itera sulle mailbox cancellando messaggi vecchi # per default, nel cestino 30gg e Spam 15 gg # # MySQL details HOST="127.0.0.1"; USER="put_here_your_mysql_user"; PWD="put_here_your_mysql_password"; MYSQL="/usr/bin/mysql"; # dovecot details DOVEADM="/usr/bin/doveadm"; TEMPFILE=$(/bin/mktemp) # Output sql to a file that we want to run echo "use postfixadmin; select username from mailbox" > $TEMPFILE # Run the query and get the results (adjust the path to mysql) results=$($MYSQL -h $HOST -u $USER -p$PWD -N < $TEMPFILE); # Loop through each row for row in $results do echo "Purging $row Trash and Junk mailbox..." # Purge expired Trash $DOVEADM -v expunge mailbox Trash -u $row savedbefore 30d # Purge expired Spam $DOVEADM -v expunge mailbox Spam -u $row savedbefore 15d done rm $TEMPFILE

March 5, 2014 · Andrea Manzini

number of physical sockets and cpu cores

a small script to check out the number of processors in your linux machine mandatory sample output:

September 14, 2013 · Andrea Manzini

Automate Cisco ssh connections with plink in Windows

A quick and dirty way to send a bunch of commands to any ssh device (in my case, Cisco appliances)… create a plain old batch file with commands echoed inside: execute the batch, piping its output to plink.exe (putty command link ssh client): c:\> commands.bat | plink -ssh -l username -pw password 11.22.33.44

May 27, 2013 · Andrea Manzini

semplice rate limit in Sinatra

Giocando con Sinatra ho avuto l’esigenza di servire una determinata pagina solo con un certa frequenza (tecnicamente un rate-limit); la cosa si puo’ fare installando il middleware Rack:Throttle ma non volevo aggiungere un’altra gemma alle dipendenze… In questo esempio se al server arriva piu’ di una richiesta in un intervallo di cinque secondi, rispondiamo a tono… SECONDS_BETWEEN_REQUEST=5 enable :sessions def ratelimit? now=Time.new.to_i session['lastrequest']||=0 #inizializza se non presente result=(now-session['lastrequest'])<SECONDS_BETWEEN_REQUEST #passati dall'ultima richiesta ? session['lastrequest']=now # aggiorna return result end get '/' do if ratelimit? return "<h1>sorry, rate limit exceeded!</h1>" end "<h1>hello!</h1>" end

December 21, 2012 · Andrea Manzini