The Linux Page

Filtering a mailbox with formail and procmail

I had to delete many emails that ended up in my archives.

When I received an email from postfix, I have a virtual entry that looks like this:

alexis@example.com    archive@archive.example.comarchive@archive.example.com

example.com is the main mail server receiving all the external mail.

archive.example.com is a separate system where mail gets sent for archival.

The archival happens in /var/mail/archive and when the file grows over a certain size, it gets compressed and saved in a different location.

The files are therefore mailbox like. Emails are written one after the other with a From to start each email.

...

How do I get the motherboard, memory, etc. info from the command line?

dmidecode to retrieve information about your hardware

The Linux system offers a set of commands that allow you to read manufacturer information from the command line.

These are decoded as DMI data.

The motherboard info is listed with:

sudo dmidecode --type baseboard | less

The output should at least include a Manufacturer name and a Product Name. The Product Name would be the motherboard name as defined by the manufacturer.

You can also find memory information with:

sudo dmidecode --type memory | less

You should get a list of  DIMM slots with information about whether those slots are filled with a DIMM or not. Those with a DIMM ...

Upgrade from 18.04 or 20.04 to 22.04 and MPI packages...

What's the Issue?

It looks like there was a bug in the MPI binary package where some alternative created a "same link" issue.

alternatives: error: /var/lib/dpkg/alternatives/mpi corrupt: slave link same as main link

The error says that an "update-alternatives ..." command found an issue trying to create an alternative where the alternative is actually not an alternative.

Did the Upgrade Work?

If you saw many other installations going and this is the last thing you see, then yes, you have your OS upgraded to the newer version. You can reboot and do whatever, ...

Useful Docker Commands

Retrieve a Docker Image

You found an image and you have a URL now you want to get a copy, you do a pull like so:

docker pull gcr.io/distroless/static

It will load that image in docker.

List Files in a Docker Image

I often would like to see the files inside a docker image. The fact is that Docker has a tarball of those files that one can export to see said files.

First you can try the save command like so:

docker save <image-uuid> > foo.tar

If that doesn't seem to work, you can try the following few steps to check out your image contents by first creating a ...

Parallelize a process in bash

Run processes in parallel in a bash script.

The other day, I worked on creating a video which means extract over 4,000 frames and then processing those frames. One of the processes is to overlay one image over another (using convert from ImageMagick). This process is very slow because each time the convert tool reloads the background image and the movie frame to overlay... so I thought I should run these commands in parallel. After all, I have 64 CPUs, let's use them!

In bash, there is a special option on the wait command: -n. This option means: wait for any one of the currently running jobs to finish. This is quite practical ...

How do I find the vim editor that locks my file?

Files piling up...

Once in a while, when I try to open a file, I get an error message saying that the file is already being edited in another instance of vim. I often have over 10 instances of vim opened so it makes it rather complicated to find out which one is the culprit.

In most likelihood, the error message includes all the information that you need. Here is an example:

E325: ATTENTION
Found a swap file by the name "/etc/apache2/sites-available/.linux.m2osw.com.conf.swp"
          owned by: root   dated: Fri Jan 22 16:19:51 ...

Create rules to protect you from a SYN flood attack

Flood waters, how a hacker can generate so many connections that your server runs out of ports.

Issue

I found an interesting concept which is to block a user¹ when they attempt to open too many TCP connections within one minute.

This comes down to a couple of rules:

iptables -A INPUT -p tcp \
    -m recent --update --name synflood --seconds 60 --hitcount 100 \
    -m tcp --syn -j add_to_denylist
iptables -A INPUT -p tcp \
    -m recent --set --name synflood -m tcp --syn

The second rule says to add an entry for the source IP in a table named synflood if the user is attempting to connect using the TCP protocol.

The first rule checks whether the same IP ...

Installation of Debian package with file moved from one package to another

Duplicated files can cause double the trouble when part of a dependent package.

Today I tried to install a new version of a Debian package I created.

That package, let's call it A, now depends on another new package, let's call it B.

A included a file that was installed under /etc/... I removed that file from A because it is also present in B. In other words, the exact same file was being installed by two packages:

  • A (old version)
  • B

Unbeknownst to me, when you try to do so, dpkg gets confused because A also included:

Depends: B

My idea was that since the new version of A does not include the file, it will get removed and then B gets ...

My hard drive looks full but I have nearly nothing installed and just a few dockers...

Istanbul, it's full.

Where Did My Disk Space Go?

I suppose with the title on this page, you already understood that Docker is the culprit... Yep! It's using a lot of disk space to store all of those images. One image can very easily be over 1Gb and if you have a VirtualBox system with many images, you end up eating a lot of your disk space very quicly!

How Did You Discover the Issue?

I ran the following command:

sudo ncdu -qx /

Did some other work for a little while, then checked the results. By default, the largest folder was shown at the top:

/var

You can simply select the folder and hit ...

Sending commands to gvim from your console

Pigeon deliverying a message

It is possible to send a command to a running gvim instance.

Here is an example on how to send a Write + Quit:

vim --servername GVIM --remote-send '<C-\><C-N>:wq<CR>'

As we can see, the syntax for the command is very similar to what we usually have in our macros.

The name "GVIM" is what you need to use (i.e. it's not the name of the server on which the gvim editor is running (a.k.a. NOT localhost).

I have not yet tested if I have multiple windows, would the instructions be sent to all or just one. I suppose I should look at the documentation ...