GNU and UNIX Commands: Sending HTML-formatted email from the Command Line

Some brief notes I made on sending HTML mail (with an optional attachment) from the command line.

GNU and UNIX Commands: Find Out Which Ports a Program is Listening on

This is easiest done with lsof. On Solaris you can use pfiles, and you may also find netstat -anlp on Linux useful.

First, find the PID of the process you’re interested in

Then, run lsof against the PID

Port 1589/UDP, that’s the information we wanted.

GNU and UNIX Commands: grep with AND instead of OR

We all know how easy it is to grep for something OR something_else:

However, there’s no elegant way to grep for something AND something_else:

Easiest way around this (and most elegant) is with awk:

Files and Filesystems: Remove Files With Strange Filenames

If it is a file that is called ‘ ‘, i.e. a single space, you can delete it a couple of ways:

Also, it might actually be some kind of control character … observe:

Easy to remove with the same find . -inum technique above.

If the file starts with a - character, e.g.:

try removing it:

Obviously it’ll whinge about -foo not being an option … so:

That’ll do it. -- tells the command to stop interpreting arguments as options. You can use this technique with other commands too, e.g. mv, file, etc.

How To Configure Solaris 10 BIND Chroot

Disclaimer: This post was originally posted in 2008 as an article on the now-defunct website zazzybob.com. While the software version and actual commands used may vary, the concepts are still similar and give a general idea of how to approach a given problem.

The default BIND installation in Solaris 10 does not run in a chroot environment, which is an obvious security risk. Starting BIND to run in a chroot environment is a no-brainer, but getting it to managed by SMF in Solaris 10 requires a bit more work …

Continue reading

Files and Filesystems: Core Files

Note: This tip assumes that you’ve checked the filesystem for legitimate files called core before running the scripts/commands contained herein! See the bottom of this article for how to do that.

Coredumps are created when a program crashes and dumps the contents of memory at the time of the crash to disk. Left unchecked, coredumps can quickly become a problem, consuming vast amounts of disk space.

You can find and remove core dumps with a command such as:

This is fine for a quick fix, but for a longer-lasting solution you can do one of two things. If your OS/Shell support it, you can add the following line to /etc/profile for POSIX compliant shells to disable core dump generation:

(For the C shell, add the line “limit coredumpsize 0” to /etc/csh.login).

If your OS/Shell doesn’t support this, you can still tackle the problem as it happens. Most core files appear in users home directories. Running a quick script such as:

will ensure that any core file on the system is truncated to zero bytes and marked read-only, so that the core file cannot be re-created and thus will never be larger than 0 bytes. Obviously, this is a very kludgy solution, and to work efficiently, you’d need a zero byte core file in everyone’s home directory (and anywhere else on the system coredumps are found), but suffices on very old systems where ulimit isn’t available. Run from cron on a nightly basis, this can be a very useful technique on old systems.

A much more robust way of searching for and deleting core dumps is with a command like:

If you want to be cautious, then change the rm -f to rm -i.

If you’re using a system other than Solaris, you may need to modify the regex in the awk command to match whatever the output of the file command gives you when executed against a core dump.

We can see this in action here…

As you can see, it’s only removed the true core dump.

How to Change the UID of a Running Process

Recent versions of Solaris come with a suite of tools known as the “/proc” tools, which list and/or modify process information in the kernel-maintained /proc filesystem. One of these tools, pcred, can be used to change (among other things) the UID of a running process, e.g.:


If you run a man proc, you’ll receive the manual page for the /proc tools - highly useful.

Shells: Using vi-mode Line Editing in tcsh

Just a quick one. If you think emacs is a bunch of crap (like me), you’ll hate the way that tcsh defaults to using this Meta-key-ridden abomination for line editing. Let’s enable vi-mode line editing:

Ahhh, that’s better.

To make this persistent, just add it to ~/.cshrc_local:

Job done. Better yet, don’t use tcsh!

SSL - How to Check an HTTPS webserver

It’s easy to telnet to port 80 on a “standard” non-SSL webserver, and issue a GET / in order to verify that the webserver is responding correctly. But how to do it over SSL? Just use the s_client command via the openssl tool.


You’ll see details of the certificate chain displayed (as well as any errors), and you can then issue your GET / to test the webservers operation.

You can also use this tool to test other SSL-enabled services (such as IMAPS/POP3S).