Linux

How to remove all messages from Exim's mail queue


# list messages in the queue
exim -bp
# remove a single message
exim -Mrm 1RsGHp-0008Kz-6P
# remove all messages
exim -bp | exiqgrep -i | xargs exim -Mrm

How to tell which processes are going to be killed first by the linux kernel's OOM killer

If an OOM (Out-Of-Memory) event occurs (the system runs out of allocatable memory), the linux kernel invokes the oom-killer which uses an algorithm (as described in the kernel docs) to select some processes to be killed and thus free some memory.

DiffMerge - cross-platform visual diff tool

DiffMerge is an application to visually compare and merge files within Windows, Mac OS X and Linux.

  • Graphically shows the changes between two files. Includes intra-line highlighting and full support for editing.
  • Graphically shows the changes between 3 files. Allows automatic merging (when safe to do so) and full control over editing the resulting file.
  • Performs a side-by-side comparison of 2 folders, showing which files are only present in one file or the other, as well as file pairs which are identical or different.
  • Right-click on any two files in Windows Explorer to diff them immediately.
  • Rulesets and options provide for customized appearance and behavior.
  • Compatible with 42 different character encodings.
  • Identical feature set on Windows, Mac OS X, and Linux.


Aggregate processes based on name (~command) and sort in decreasing order of a "top" column

The top command has lots of useful columns, but since many applications run multiple worker processes (eg. webservers like Apache), it's a bit difficult to see the big picture. The following one-liner aggregates a selected column in the output of top by the process name (ie. the COMMAND column) and sorts the result in decreasing order:
top -b -n 1 | tail -n +8 | awk '{ col=$6; if (match(col, "^[0-9]+m$")) { col = 1000 * substr(col, 1, length(col) - 1) }; stat[$12] += col } END { for (i in stat) { print stat[i] ": " i } }' | sort -rn | head -n 20

How to set I/O scheduler of a block device using udev rules

Eg. to set scheduler of iSCSI and FiberChannel devices:
[root@server ~]# vi /etc/udev/rules.d/95-san.rules

# To Set "noop" as I/O scheduler for iSCSI and Fiber Channel devices
ACTION=="add", ENV{ID_FS_USAGE}!="filesystem", ENV{ID_PATH}=="*-iscsi-*", RUN+="/bin/sh -c 'echo noop > /sys$DEVPATH/queue/scheduler'"
ACTION=="add", ENV{ID_FS_USAGE}!="filesystem", ENV{ID_PATH}=="*-fc-*", RUN+="/bin/sh -c 'echo noop > /sys$DEVPATH/queue/scheduler'"

How to suppress opening a browser in a python script

Some Python scripts use the webbrowser module to launch a browser for a given URL. If you're on a headless server, it'll launch a text-based browser (eg. in Debian it's w3m) which might not be desired (many websites are less than usable in text-based browsers and the launch of such an URL in a text-based browser is more an annoyance than help). You can easily avoid this behaviour.

GoogleCL - command line tools for the Google Data APIs

"GoogleCL brings Google services to the command line.
We currently support the following Google services: (...)"


Using awk/sed to detect/remove the byte order mark (BOM)

BOM is nothing more than a nuisance. Detecting and removing it is plain simple. There's a utility called bomstrip that pretty much does what is says and there's the one-liner AWK implementation that you find on stackoverflow (I've added whitespaces for better readability):
awk '{ if (NR == 1) sub(/^\xef\xbb\xbf/, ""); print }' INFILE > OUTFILE
Or a sed version (replaces in place):
sed -i -e '1s/^\xEF\xBB\xBF//' FILE
To do this (or just simply detect BOM) recursively in a dir, you'll find tons of ideas in this other stackoverflow article.

TCP Catcher

I've already written about a number of web debugging proxies (Charles, Fiddler, Paros) and now I've stumbled on another one. Smiling TCP Catcher comes as a simple JAR (yes, this one is written in Java too, just like Charles) and has a lot less features than Fiddler or Charles. However less is sometimes more. It consists of only two screens: settings page and request (TCP or HTTP) list. It's very easy and fast to set up and works quite well. If you don't need the rich feature set of Charles, TCP Catcher is the way to go. Smiling

Syndicate content