[Exim] cheatsheet

This post is a partial copy of this article.

—————————————————————————————————————

Message-IDs and spool files

The message-IDs that Exim uses to refer to messages in its queue are mixed-case alpha-numeric, and take the form of: XXXXXX-YYYYYY-ZZ. Most commands related to managing the queue and logging use these message-ids. There are three files for each message in the spool directory. If you’re dealing with these files by hand, instead of using the appropriate exim commands as detailed below, make sure you get them all and don’t leave Exim with remnants of messages in the queue.

Files in /var/spool/exim/msglog contain logging information for each message and are named the same as the message-id. Files in /var/spool/exim/input are named after the message-id, plus a suffix denoting whether it is the envelope header (-H) or message data (-D). These directories may contain further hashed subdirectories to deal with larger mail queues.

Basic information

Print a count of the messages in the queue:

# exim -bpc

Print a listing of the messages in the queue (time queued, size, message-id, sender, recipient):

# exim -bp

Print a summary of messages in the queue (count, volume, oldest, newest, domain, and totals):

# exim -bp | exiqsumm

Print what Exim is doing right now:

# exiwhat

Test how exim will route a given address:

# exim -bt alias@localdomain.com

Run a pretend SMTP transaction for a given IP:

# exim -bh 192.168.11.22

This will display Exim’s checks, ACLs, and filters as they are applied. The message will NOT actually be delivered.

Display all of Exim’s configuration settings:

# exim -bP

Searching the queue with exiqgrep

For messages from a specific sender:

# exiqgrep -f [luser]@domain

For messages for a specific recipient/domain:

# exiqgrep -r [luser]@domain

Print messages older than than 1 day:

# exiqgrep -o 86400 [...]

For messages less than an hour old:

# exiqgrep -y 3600 [...]

There are also a few flags that control the display of the output. Use -i to print just the message-id. Use -c to print a count of messages matching the condition.

Managing the queue

Remove a message from the queue:

# exim -Mrm <message-id>

Freeze a message:

# exim -Mf <message-id>

Thaw a message:

# exim -Mt <message-id>

Deliver a message, whether it’s frozen or not, whether the retry time has been reached or not:

# exim -M <message-id>

Deliver a message, but only if the retry time has been reached:

# exim -Mc <message-id>

Remove all frozen messages:

# exiqgrep -z -i | xargs exim -Mrm

Remove all messages older than five days (86400 * 5 = 432000 seconds):

# exiqgrep -o 432000 -i | xargs exim -Mrm

Freeze all queued mail from a given sender:

# exiqgrep -i -f luser@example.tld | xargs exim -Mf

View a message’s headers:

# exim -Mvh <message-id>

View a message’s body:

# exim -Mvb <message-id>

View a message’s logs:

# exim -Mvl <message-id>

SSH through HTTPS proxy

connect-proxy is a simple relaying command to make tunnel TCP connection via SOCKS4/5 or HTTPS proxies. It is mainly intended to be used as proxy command for OpenSSH. To use it first install the appropriate package, connect-proxy on GNU/Debian.

Then adjust your ssh configuration:

# vi ~/.ssh/config 
Host 10.10.1?.* 10.10.2?.* 10.10.3?.* *.foobar.fr
   User root
   ProxyCommand connect-proxy -H 10.2.0.217:3128 %h %p

Here in order to reach these specific hosts we connect through an HTTPS proxy on the port 3128 of the machine 10.2.0.217 Note that you can also use other program, like corkscrew instead of connect-proxy.

[Debian] Disable a service

In the Debian world, the usual method to remove a service from startup without uninstalling the package, is to delete the init’s script symlinks like this:

update-rc.d -f remove foobar

Problem: at the next package upgrade, the post-install script will recreate the symlinks. Fortunately update-rc.d has a lesser-know disable option for this precise use case:

update-rc.d -f disable foobar

[OpenVZ] iptables: Memory allocation problem

Let say you add a new iptable rule inside an container, but this time this happen:

# iptables -I INPUT -s 123.123.123.123 -j DROP
iptables: Memory allocation problem

Where does it come from ?

You probably hit the limit of the numiptent parameter. Check its failcounts:

# egrep "failcnt|numiptent" /proc/user_beancounters

If it’s greater than zero, you have your answer.

Increase the limit

On the host you can redefine the limit (soft and hard) for a container like this:

# vzctl set VPS_ID --save --numiptent 800:1000

Here i double default values.

[MySQL] Limit connection per user

Is a single website wreaking havoc on your MySQL server by saturating all its sockets ? If so you need to set in place some limits.

The max_user_connections variable

You are likely familiar with the max_connections setting, but there is also the less know max_user_connections. Its name is self-explanatory.

Limit for a specific user

If you need to be more granular, it’s also possible to limit connections for a specific user, like this:

GRANT ALL ON DBNAME.* TO XXX@YYY with MAX_USER_CONNECTIONS 100;

You can use other limit options like MAX_QUERIES_PER_HOUR, MAX_UPDATES_PER_HOUR or MAX_CONNECTIONS_PER_HOUR depending your needs.

Usual environment variables

Unix system use a lot of environment variables. Most of them are initialized when you log in and are maintained until you log out. This is a list of the most usual/usefull variables to know. Keep in mind, depending on the OS/distribution and your shell, some may or may not exist:

PATH – List directories the shell searches for commands
HOME – User's home directory
TERM – Indicate which terminal emulator is used
PS1 – Shell prompt in the Bourne shell and variants
MAIL – Path to user's mailbox
TEMP – Path to directory where processes can store temporary files
TZ – Timezone settings
PWD – Path of the current directory
HISTFILE – Name of the file in which command history is saved
HISTFILESIZE - Maximum number of lines contained in the history file
HOSTNAME - System's host name
LD_LIBRARY_PATH - List of directories where libraries should be searched for
USER - Current logged in user's name
DISPLAY - Network name of the X11 display to connect to, if available
SHELL - Indicate current shell path
TERMCAP – Display termcap database entry for the current term
OSTYPE – Type of operating system
MACHTYPE – The CPU architecture that the system is running on
EDITOR – The user's preferred text editor
PAGER –	The user's preferred text pager
MANPATH – List of directories to search for manual pages

You can also list all the environement variables on your current session, using the printenv command.

[MySQL] Dump only triggers and stored procedures

By default mysqldump backup triggers but not stored procedures. For that you must add the --routines option.

But how do you do to dump only triggers and stored procedures ?

Like this :

mysqldump --routines --no-create-info --no-data --no-create-db --skip-opt <database> > <dump>.sql

[MySQL] Dump with one INSERT statement for each data row

By default mysqldump make a dump with only one INSERT statement per table. This is efficient but annoying as hell when you need to debug a failed import.

In that case i recommend you to redump the problematic database with the option --extended-insert=FALSE to get a dump with one INSERT statement for each data row.