Andrew Latham

Cleaning up a postfix mail queue is both dangerous and important when situations require it.

There will come a time when every admin needs to preform magic. This is some magic to remove emails from a Postfix queue when you have hundreds of thousands of emails and the mailq command can't finish.

mailq | awk 'BEGIN { RS = "" } /' | sed 's/!//' | postsuper -d -

In laymans terms, this script runs the mailq program and starts working on the output. This is both dangerous and fast. AWK jumps in and gets the mail ID and then SED will trim out the ! character if it is present, lastly the postsuper -d will delete what ever it gets. Change for whatever source of spam you are getting. If it is a country code you are having problems with you can do ".cc" for the TLD. Please use with caution.

Andrew Latham

Sparse files are handy but at times difficult to work with.

When you need to move large sparse files across the network there are many issues related to support of this new FS method. Sparse files are files that say they are size X but only allocate blocks on the file system that are actually used. This is a great use of space and very nice for virtualization. In the past methods like COW to only use space as it was needed. These solutions worked. Sparse file support was integrated into the Linux Kernel and now it is the preferred way to handle images.

Andrew Latham

Developers on various platforms can often unknowingly introduce encoding issues on files. Here is a solution to one problem.

Simple one liner to remove all ^M line returns from files in a directory. I use this on an Open Source project I work on mainly for PHP files. Type "CTRL v" then "CTRL m" to get the system ^M char. The character will not copy and paste. The filter for SVN is optional and insert CVS or git for your SCM of choice.

grep -IUrl "^M" * | grep -v svn | xargs sed -i 's/^M$//' Easy! Search the directory recursively. Filter out the SVN files. Run SED against the files in the list.

Andrew Latham

Python CLI Webserver

If you ever need or want to create a webserver with the files in the current directory listed then just use this little snippet.

python -m SimpleHTTPServer

It will inform you of the address it is listening at or you can set the port via

python -m SimpleHTTPServer 8080

With Python 3 you might want to use:

python3 -m http.server

The same method of setting the port with Python 3 too

python3 -m http.server 8080