Mboxgrep Installation on Solaris 10

I needed to find a message in my mailbox on a Solaris system. I was fairly certain I still had the message, which I thought I probably wrote almost a year ago in March of 2005, but I couldn't find it when I searched through messages I still had in my mailbox from March and April of 2005. In Pine, which I normally use to read my email, I also searched for likely words in the subject, but still couldn't find the message nor could I find it when I searched by "from" address. So I tried a search of my mailbox file, which is in /var/mail, using grep. The message contained information about IBM's discontinuance of support for OS/2 and the costs to upgrade a circuit matrix switch that is still controlled by PCs running vendor-unique software under the OS/2 operating system.

I have over 18,000 messages in my inbox alone. Yes, I really do need to clean it out; I deleted a couple of hundred messages today, but that is only a couple of days worth of email. But I knew I would have few messages containing "OS/2". The grep search found a few lines in the file containing "OS/2" and from what it found it appeared I did indeed still have the message, but grep under Solaris does not provide the capability for one to see lines surrounding the one in which the search pattern is found, so I still didn't know how to locate the entire message. I tried editing the file with vi and with pico, but that was useless. The vi editor read in the file, but only part of it, because the file contained very long lines in binary attachments. I couldn't find what I needed in what vi read in. And pico also appeared to be stymied by the long lines, churning a way for a very long time while complaining about long lines.

So I decided to look for an an alternative way to search a mailbox file on a Unix or Linux system for a particular message. I found mboxgrep, The developer's website stated "mboxgrep is a small utility that scans a mailbox for messages matching a regular expression. Found messages can be either displayed on standard output, counted, deleted, piped to a shell command or written to another mailbox." The following features were listed for the program:

Features:

That seemed to be exactly what I wanted and it did work great, but getting it to run on an x86-based Solaris 10 system took a little time, not because of any deficiencies in the mboxgrep program itself, but due to the fact that the Solaris system was not yet configured to make it easy to compile and run software such as mboxgrep, e.g. the existing path for root didn't include a directory with a C compiler and there was no LD_LIBRARY_PATH that pointed to a library file mboxgrep needs, which fortunately was already on the system.

I downloaded the .tar.gz file, which you can get from freshmeat.net. I unzipped it and untarred it.

$ gunzip mboxgrep-0.7.9.tar.gz
$ tar -xvf mboxgrep-0.7.9.tar
$ cd mboxgrep-0.7.9

I tried to run ./configure from my user account, but got an error message that the "C compiler cannot create executables".

bash-3.00$ ./configure
checking for gcc... no
checking for cc... cc
checking for C compiler default output... configure: error: C compiler cannot create executables
See `config.log' for more details.

I thought I should probably go through the installation process from the root account anyway so I could install the software in a way that would make it accessible to all accounts on the system, so I logged in as root. But I still couldn't get through the ./configure step.

# ./configure
checking for gcc... no
checking for cc... no
checking for cc... no
checking for cl... no
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.

A search for C compilers on the system, such as cc or gcc showed that the cc compiler was in /usr/ucb/cc and the gcc compiler was in opt/sfw/bin, since I had installed the optional open source software components that were available from Sun when I downloaded the free version of Solaris 10.

So I looked at the path for the root account and found it didn't include either of those directories. I added /opt/sfw/bin to the path.

# echo $PATH
/usr/sbin:/usr/bin
# PATH=$PATH:/opt/sfw/bin
# echo $PATH
/usr/sbin:/usr/bin:/opt/sfw/bin

I was then able to get through the ./configure step. I then ran make, but it wasn't found, so I searched for it and found it is in /usr/css/bin/make, which I also added to the path for root.

# make
make: not found

# find / -name make -print
/usr/ccs/bin/make

# PATH=$PATH:/usr/ccs/bin
# echo $PATH
/usr/sbin:/usr/bin:/opt/sfw/bin:/usr/ccs/bin

I was then able to run make and make install successfully.


# make
cd src; make
gcc -g -O2 -I/opt/sfw/include -I. -I. -c info.c
gcc -g -O2 -I/opt/sfw/include -I. -I. -c main.c
gcc -g -O2 -I/opt/sfw/include -I. -I. -c mh.c
gcc -g -O2 -I/opt/sfw/include -I. -I. -c scan.c
gcc -g -O2 -I/opt/sfw/include -I. -I. -c maildir.c
gcc -g -O2 -I/opt/sfw/include -I. -I. -c mbox.c
gcc -g -O2 -I/opt/sfw/include -I. -I. -c misc.c
gcc -g -O2 -I/opt/sfw/include -I. -I. -c wrap.c
gcc -g -O2 -I/opt/sfw/include -I. -I. -c getopt.c
gcc -g -O2 -I/opt/sfw/include -I. -I. -c getopt1.c
gcc -g -O2 -I/opt/sfw/include -I. -I. -c md5.c
gcc -g -O2 -I/opt/sfw/include -o mboxgrep info.o main.o mh.o scan.o maildir.o mbox.o misc.o  wrap.o getopt.o getopt1.o md5.o -lbz2 -lz  -L/opt/sfw/lib -lpcre

# make install
cd src; make install
/opt/sfw/bin/ginstall -c -d /usr/local/bin
/opt/sfw/bin/ginstall -c -s mboxgrep /usr/local/bin
cd doc; make install
/opt/sfw/bin/ginstall -c -d /usr/local/man/man1
/opt/sfw/bin/ginstall -c -m 0644 mboxgrep.1 /usr/local/man/man1
/opt/sfw/bin/ginstall -c -d /usr/local/info
/opt/sfw/bin/ginstall -c -m 0644 mboxgrep.info /usr/local/info

The program was installed in /usr/local/bin as mboxgrep. I logged off the root account and then attempted to run it on my mailbox file from my normal user account. I searched for the word "defunct", since I knew it was present in the message about OS/2, but wasn't likely to be present in many other messages.


bash-3.00$ /usr/local/bin/mboxgrep defunct /var/mail/jim
ld.so.1: /usr/local/bin/mboxgrep: fatal: libpcre.so.0: open failed: No such file or directory
Killed

So the program needs libpcre.so.0, but it wasn't found. I searched for that file and found it in /opt/sfw/lib/libpcre.so.0. So I pointed the LD_LIBRARY_PATH to it after first checking to see if there were any other directories already in that path.


bash-3.00$ echo $LD_LIBRARY_PATH

bash-3.00$ LD_LIBRARY_PATH=/opt/sfw/lib ; export LD_LIBRARY_PATH
bash-3.00$ echo $LD_LIBRARY_PATH
/opt/sfw/lib

Note: you won't have an /opt/sfw directory and thus no /opt/sfw/lib/libpcre.so.0 directory unless you downloaded the "Companion DVD" and installed the software on it. The Companion DVD, which is available from Solaris Operating System - Freeware contains open source software that you can use with the Solaris operating system. Alternatively, you can download just the packages you want from the same URL. Or you can get just libpcre.so.0 here. This file is from a PC running the x86 version of Solaris, not a SPARC version of Solaris.

After I set the LD_LIBRARY_PATH variable I was then able to run mboxgrep.


bash-3.00$ /usr/local/bin/mboxgrep
Usage: mboxgrep [OPTION] PATTERN MAILBOX ...

Try `mboxgrep --help' for more information.

According to information in the leafnode readme.txt file, you can make the LD_LIBRARY_PATH permanent with the crle utility (use man crle for further information). Setting LD_LIBRARY_PATH allows you to deliberately override the built-in library path of executables.

I searched for the word "defunct" again and redirected the output to a file. When I edited that file I found that mboxgrep had done exactly what I hoped it would do. It found every message in my mailbox with the word "defunct" in it and placed the entirety of each of those messages in the file.

bash-3.00$ /usr/local/bin/mboxgrep defunct /var/mail/jim > OS2-defunct-msgs.txt

When I attempted to get further information for mboxgrep with man, I found that the MANPATH variable was not set correctly for my account to get that information, since the manual page is at /usr/local/man/man1/mboxgrep.1, but the value for the MANPATH variable does not include the /usr/local/man directory.


bash-3.00$ man mboxgrep
No manual entry for mboxgrep.
bash-3.00$ echo $MANPATH
/usr/dt/man:/usr/man:/usr/openwin/share/man

But I could get the information by specifying an alternate directory to search under for manual pages.

bash-3.00$ man -M /usr/local/man mboxgrep

The mboxgrep man page is here.

References:

  1. leafnode readme.txt