Andrew Watters

Random Linux tips and tricks

Look up DNS record for each IP address in webserver log file

cat logs/ | grep "Vision" | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | nslookup | grep "name ="

Returns a list of all the hosts in my server access log that accessed a PDF with Vision in the title.

Solving "body hash did not verify" error with DKIM when trying to send attachments from a PHP script

Wrap the long lines of the Base64-encoded data to 78 characters and break with a newline character (\n):

<? wordwrap($attachment,78,"\n",true); ?>

Now your DKIM signature will be valid because the message body is intact when signed.

Install libmilter on Linux

This is really annoying: libmilter is only available if you download the Sendmail source code and manually build it. Here you go:


tar -xvzf sendmail-current.tar.gz

cd sendmail-8.15.2

cd libmilter



sudo make install

That's it! Now when you try to install opendkim, you won't get error messages about libmilter being missing.

Create subtitled video with album art and high resolution audio

ffmpeg -framerate 1 -loop 1 -i final-cover.png -i album.ogg -acodec copy -vcodec libvpx-vp9 -crf 20 -b:v 0 -vf subtitles=album.ass -shortest album1.webm

This assumes you already have a high resolution opus/ogg file of the album. The album.ass file is the subtitle file, which can be done using gnome-subtitles or something more advanced such as Aegisub. Further details here. I selected the VP9 codec for compatibility and opus/ogg audio for best quality audio and broad compatibility.

Merge, split, and/or Bates stamp PDF files on Linux

Seriously, this is one of the hardest things I have ever done. Finding the right tool was half the challenge.

I am pleased to recommend CPDF, which is free for personal and non-commercial use, but otherwise does require a license (worth it).


Merge is the default operation:

cpdf -merge file1.pdf file2.pdf -o file.pdf

Split into n-page chunks

cpdf -split -chunk 20 file.pdf -o piece%%%.pdf

Unfortunately, neither CPDF nor PDFTK can apparently split a file based on file size of the resulting chunks. This is extremely frustrating when there are file size limitations on certain courts' electronic filing systems. The solution I use is to count the number of pages (cpdf -pages file.pdf), divide by the file size in megabytes, split the PDF using that number of pages per chunk, then manually combine the resulting chunks until they are just under the file size I want. Frustrating, and begging for automation. I could probably write a script to do that, but it would be nice if there were a tool already out there.

Bates Stamp

This knowledge took me over a year and a half to obtain. I present it here for free to save others time.

cpdf -add-text "%Bates" -bates 1 file.pdf -bottomright 30 -o stamped.pdf

Change a RHEL 7 system from graphical login to shell login, and then start KDE

localhost$ sudo systemctl enable

localhost$ reboot

[After rebooting]

localhost$ startx /usr/bin/startkde

You would not believe how long it took me to figure that out. If you just do startx, it will freeze your system if there are any problems with GNOME.


Last updated: August 3, 2019

© Andrew G. Watters