No frikin tables...
Friday 30th 2010f July 2010 01:17:51 PM
Codes
Here i will be posting all the little codes that i wrote my self. All the codes in this section are GPL, unless specified otherwise. Most of the codes work on Linux/Unix. You can try it out on windows (if its something like Python, C etc). Obviously Bash scripts won't work, unless you install cygwin.
I used this thread from the Postfix Admin forum to modify the latest version of postfix admin, which is 2.1.0, to work with cyrus-imap.

Hopefully this works. The patch was reasonably easy to transfer to the latest version.

If anyone wants to comment just use the above forum.

postfixadmin-2.1.0-cyrus-imap Download

After finding that the number of users using my email server was growing i had to find a better way of running fetchmail, a more efficient way.

Usually i would create a cron job for each user this cron would run fetchmail every few minutes.
Being the nature of fetchmail, the daemon only works if you create one config file for everyone, which means adding everyones username and password in one file.
This does not help anyone if they want to edit their own files, becuase this global file is only writable by root.
So cron was the only way to do this.

However, i wrote this script so that i only need one cron, and then i just run this one script when ever i want. Simple.
It also takes the load off the server, since there is only one fetchmail running at any given time.

Set cron up so that it runs this script every 10 minutes:
*/10 * * * * /usr/bin/fetchmailForAll.sh >/dev/null 2>&1

fetchmailForAll.sh View Download
This script goes hand in hand with the spamassassintrainer (you'll find it in my website).

After finding that the number of users using my email server was groing i had to find a better way of running the trainer script, a more efficient way, so that my server does to get bogged down when 10 users start running the trainer at the same time. So this script was devised to run the trainer for specific users in my server, every 2 hours.
This saved a lot of work for me, adding a new cron job for every new user and stopped my server slowing down every hour.

Its a very simple script, and works very well.
Set cron up so that it runs this script every 2 hours:
0 */2 * * * /usr/bin/spamassassintrainerForAll.sh >/dev/null 2>&1

spamassassintrainerForAll.sh View Download
This is a script i use to start multiple bittorrent downloads.
Basicly i've edited the btdownloadcurses.py file so that it exits after a complete download. Then this script runs many downloads one after the other, so that multiple downloads is possible, without any intervention.
I must say it works very well. It keeps a log and appends the torrent files with .OLD so that it does not get redownloaded.
There is also some nice colourful outputs, just to complete the whole script :)
I have included the btdownloadcurses.py file too, so that people can see what i did.
Just make sure the finished method looks like this:
def finished(self):
self.done = 1
self.activity = 'download succeeded!'
mainkillflag.set()
self.downRate = '%s/s down' % (fmtsize(0))
self.display({'fractionDone': 1})

The important part of the code above is:
mainkillflag.set()

which basicly exits the download.

The script is very easy to use:
$ btdir .

will download using all the torrent in the current directory.
$ btdir ./Download

This will use all the torrents from ~/Download.
btdir.sh View Download
btdownloadcurses.py View Download
This scripted was created to teach SpamAssassin using sa-learn about spam and ham (non-spam). The script is fairly dynamic, it requires 3 folders that are .Spam, Spam.Spam, Spam.Ham. The Spam.Spam and Spam.Ham folders are there if the spam filter makes a mistake, the user should manually move the email to the correct folder, so that sa-learn can learn to correct the mistake. The ham then gets redirected to procmail, once it has re-learnt the email, so procmail can filter it to the correct folder instead of the spam folder. The spam, if detected, gets moved straight to the .Spam folder. The script is dynamic in a way that it will learn ALL folders that are inside ~/.maildir and has . (dot) in front of the name as a ham folder.

Warning, this includes the .Trash folder. So make sure you always put spam email to either the .Spam folder or .Spam.Spam folder. The emails inside .Spam.Spam folder will be re-learnt, so that this mistake does not happen again.

Make sure you save this somewhere like /usr/bin/spamassassintrainer, and then:
chmod +x /usr/bin/spamassassintrainer

So that you can excecute the file. The best way use this script is using cron. Set cron up so that it runs this script every 2 hours, or something:
0 */2 * * * /usr/bin/spamassassintrainer >/dev/null 2>&1

There's no point in running it too many times. The spams not going anywhere ;-)
spamassassintrainer.py View Download
I have been trying to find a way of backing up my work, from the univerisities filestore, to my Laptop, or Server. After trying out a number of different programs i've decided to use rsync to synchronise the universities filestore with my server's account. I also installed rsync in my laptop, and i synchronise between my laptop and server.

The way this works is that when i login into my universities account, i run an UpdateWork.sh script. Which updates all the files inside the ~/Work directory with my ~/Work in my server. Then when i finish working, i then run an UploadWork.sh script which does the opesite, synchronises my server's ~/Work with the uni's ~/Work. Me being lazy, and very forgetful, i setup openbox todo this automaticly, every time i login and everytime i press the exit button on the menu. I've created RSA ssh id's, that allow me to use ssh-agent to lgin without typing in a password.

I'll try and improve these scripts, to include either cvs or subversion concurrent backup feature, along with rsync. This will allow me to go back and get a previous version of a file. Also these files are just source codes for java, or normal documents. So therefore they won't get too big. I also leave these scripts inside my ~/Work folder. So when ever i change something, my server, uni and my laptop, they all get updated, when i run the script. So this works nicely.

Ofcourse this really breaks down if you forget to Upload the new files, or something. eg: in uni i started the UpdateWork.sh script. Then i created new files, etc etc. Then the Upload script did not work and openbox exited too quickly. Now when i relogged in again, the update script started. Therefore it erased all the new files that it found on the ~/Work directory. So be careful. I'll try and improve it in the future.

These scripts also works on windows, i mean if you use cygwin, and install rsync with it. Then this works just fine. It works the same was as it does on Linux.
UpdateWork.sh View Download
UploadWork.sh View Download