Archive for the ‘Software’ Category

4
Nov

msmtp – a (fairly) simple mail submission program

As an oldtime Unix guy, I’ve always been used to having the BSD mail utility to hand, and a suitably configured mail system, so that I can script jobs to run and email the results back to me. I use mail as a sort of glorified syslog facility. With smaller single board Linux computers we don’t always want to install a full mail setup – resources often tend to be limited. A few years back I discovered msmtp http://msmtp.sourceforge.net/.

This utility is an smtp client that submits a file in standard mail format to a mail server. It can submit plain text email or use TLS/SSL etc. I use a couple of script wrappers to emulate, sort of, sendmail and the sending part of the BSD mail utility.

Of course to use msmtp you need a mail server to which you can submit email for delivery. My home server is my mail server, but you could use your ISP’s smtp server. Another problem is that msmtp just fails if it can’t connect to the mail server – it’s up to you to handle that and do something else with that precious message you can’t mail just now! My sample scripts do not deal with that situation.

This very simple script I call sendmail, and it will need customising for your setup…

#!/bin/sh
#

# set these for your setup...
MailServer=mail.server
Domain=MachineName
From="me\@my.domain.com"

exec msmtp --host=$MailServer --domain=$Domain --from=$From $*

This is my simple script to emulate the simple parts of the send functionality in the BSD mail utility. It has many shortcomings, but it has served me well…

#!/bin/sh
#
# A sort of shell replacment for the send functionality of
# the standard "mail" utility.
#
# mail [-s subject] recipient(s)
#

u=`id -un`
d="my.email.domain"
r=""
s=""
v=""

while [ $# -gt 0 ]; do
 p="$1"
 shift
 case "$p" in
 -s)
        s="$1"
        if [ $# -gt 0 ]; then shift ; fi
        ;;
 -v)
        v="-d"
        ;;
 -*)
        echo 1>&2 "Option \"$p\" not recognised."
        exit 1
        ;;
 *)
        r="$r , $p"
        ;;
 esac
done
if [ "$r" = "" ]; then
 echo 1>&2 "No Recipients."
 exit 1
fi
if [ "$s" = "" ]; then
 printf "Subject: "
 read s
fi

s="Subject: $s \n"

(echo -e "From: ${u}@$d \nTo: $r \n$s \n\n"
 cat ) | sendmail -t $v

So if you have a job to run on the platform, then this will email the output to you…

my_job | mail -s “my_job output” [email protected]

msmtp can be loaded from the package systems of most distributions, but I have had occasion to cross-compile the package for installing on a system without package management. I had only limited libraries on my cross compile system, and found that after downloading and extracting the sourcecode from sourceforge, I had to cross compile without some of the advanced features. I used

./configure –build=arm –disable-ssl –disable-gsasl –disable-nls

before doing the make to build the binaries. The resultant binary just submitted plain text email, but that was ok for my use – YMMV. The resultant binary, suitably stripped,is pretty lean.

I recently revisited using msmtp to pre-test a change to my ISP’s new smtp server, before committing the change to my mailserver’s sendmail setup. It can also be useful for testing security settings etc on mail submissions systems.

Jim

4
Sep

Utility to Clean C Like Language Syntax

Check out uncrustify next time you need to stylize your c like application. Their website gives a short, concise summary of what it does. Check it out here: uncrustify on sourceforge.

It’s also highly configurable via the uncrustify.cfg config file.

Example usage:

uncrustify -c uncrustify.cfg -f source_file.c

You should be able to install it using apt-get or yum, depending on your Linux distribution.

21
Mar

Convert PDF to SWF with pdf2swf

I stumbled upon pdf2swf when looking for the best way to embed a PDF into a webpage. It works really well and was easy to compile on my shared hosting account (bluehost.com). I installed using the following steps:

Download – Download version 0.9.1 (visit http://www.swftools.org/download.html for latest)

wget http://www.swftools.org/swftools-0.9.1.tar.gz

Extract – Extract the newly downloaded files

tar xzvf swftools-0.9.1.tar.gz

Configure – Make sure the environment is setup

cd swftools-0.9.1; ./configure

Compile – Getting source to binaries

make config; make

Test Run – You should get a help menu

./src/pdf2swf

Install – Copy the binaries to proper locations on the system
(You won’t be able to run this step if you’re installing on a shared host. If that’s the case, copy the binaries of interest to ~/bin and add ~/bin to PATH variable)

make install

Usage – Run the program (Run man pdf2swf for more info)

pdf2swf myfile.pdf myfile.swf

That’s it! Open the .swf using your browser to see pdf2swf’s handywork.

As a side note, I ended up ditching the .swf method for embedding my document on my website and going with Google’s PDF viewer which is done with the following line of HTML:

<iframe style="width: 700px; height: 900px; border: 0px none;" src="http://docs.google.com/gview?url=http://mydomain.com/path/to/myfile.pdf&amp;embedded=true" width="320" height="240"></iframe>
29
Nov

Time Tracking in the Command Line (Python and Shell Scripts)

If you’re doing consulting work and/or wanting to keep track of time spent on your todo list items from a command line interface (CLI), look no further than the following two scripts. They are simple to use and have a fair amount of power and flexibility in them. The first is a shell script which tracks your todo items. The second is a Python script which wraps itself around the todo list and give you the ability to punch in and out of the task your working on. Be sure to visit the homepages of each tool to get more information.

http://ginatrapani.github.com/todo.txt-cli/
http://code.google.com/p/punch-time-tracking/

10
Nov

XML Pretty Printer

A nifty tool when dealing with misfit XML documents is XML Pretty Printer. This command line tool will do exactly as it says: print pretty XML. Example usage:

xml_pp foo.xml > foo_pp.xml

In order to install xml_pp, you’ll need to use your package manager. For example, in Fedora you use yum install perl-XML-Twig and in Debian/Ubuntu you use apt-get install xml-twig-tools.

As always, be sure to check out the man page for xml_pp.

8
Nov

Gobby: Cross Platform Real-Time Collaboration Software

Take a moment or set aside some time to check out a cross platform, real-time collaboration software program called Gobby. Here’s the standard blurb from the projects homepage:

Gobby is a free collaborative editor supporting multiple documents in one session and a multi-user chat. It runs on Microsoft Windows, Mac OS X, Linux and other Unix-like platforms.

Gobby has many excellent features and is a very promising application in terms of synchronous collaboration software. I have yet to get my hands dirty with it, but my initial thought is that this is the “missing-link” that I’ve been searching for so that I may assist or collaborate code with others. I’ve given ethercodes.com and Google docs a whirl, but they just seem clunky when it comes time to actually testing the program you’ve collaborated on (lots of copy/paste between web browser and terminal).

Looks like Linux.com has a nice article on setup and usage, so be sure to check it out for more information. I will probably try to create my own once I get the hang of it. 🙂
http://www.linux.com/archive/articles/55361

27
Oct

Mercurial SCM for Code Management Like CVS, SVN, or GIT

Mercurial is yet another open source code management system in the sea of SCM systems like CVS, SVN, or GIT. Honestly, I don’t know much about it to dive into details on setup and capabilities, but it’s something to push onto my plate for a little digestion and might be for you as well. Be sure to take a look at the main homepage to find out more: http://mercurial.selenic.com/

One capability that it has, which the others probably do as well, is that it has a fairly nice and clean looking web interface which can be hosted on your development PC or server for working with your code. I also know that in order to interact with the Mercurial SCM, you use the command ‘hg’, which is the element symbol for mercury. Clever, no? See the man pages here: http://linux.die.net/man/1/hg

3
Aug

How To: Install MySQL Query Browser in Fedora 13 (mysql-gui-tools)

As of Fedora 13, the package mysql-gui-tools is no longer available (replaced by mysql-workbench; see this page), so we’ll have to do things the hard way by digging into the archives over at http://dev.mysql.com. It’s not all that tough, but there are some issues currently (see end of post). I would like to ask others to provide any insight to the issues. So, for now, I present the beginnings of how to install MySQL Query Browser on Fedora 13…

Open the terminal, login as root with ‘su’, and copy/paste the following commands:

<br />
wget http://dev.mysql.com/get/Downloads/MySQLGUITools/mysql-gui-tools-5.0r12-linux-i386.tar.gz/from/http://mysql.he.net/<br />
tar xzvf mysql-gui-tools-5.0r12-linux-i386.tar.gz -C /opt<br />
cp /opt/mysql-gui-tools-5.0/MySQLQueryBrowser.desktop /usr/share/applications/<br />

A menu link to the program should be available under “Applications -> Programming -> MySQL Query Browser“, however if you want to run it from the terminal, use the following commands:

<br />
PATH=$PATH:/opt/mysql-gui-tools-5.0/<br />
mysql-gui-tools<br />

Now, if your luck is anything like mine, you’ll notice that if you run the program from the command line, you’ll get the initial setup window (strange looking, like theme isn’t being used), then an error message, then nothing happens after filling out the setup information. The error message will probably look something like:

<br />
[[email protected] ~]# /opt/mysql-gui-tools-5.0/mysql-query-browser<br />
/usr/share/themes/Clearlooks/gtk-2.0/gtkrc:55: error: unexpected character `@', expected string constant<br />
Fontconfig warning: &quot;/etc/fonts/conf.d/65-fonts-persian.conf&quot;, line 190: invalid match target &quot;scan&quot;<br />
Fontconfig warning: &quot;/etc/fonts/conf.d/65-fonts-persian.conf&quot;, line 199: invalid match target &quot;scan&quot;<br />
Fontconfig warning: &quot;/etc/fonts/conf.d/65-fonts-persian.conf&quot;, line 208: invalid match target &quot;scan&quot;<br />
Fontconfig warning: &quot;/etc/fonts/conf.d/65-fonts-persian.conf&quot;, line 217: invalid match target &quot;scan&quot;<br />
Fontconfig warning: &quot;/etc/fonts/conf.d/65-fonts-persian.conf&quot;, line 226: invalid match target &quot;scan&quot;<br />
Fontconfig warning: &quot;/etc/fonts/conf.d/65-fonts-persian.conf&quot;, line 235: invalid match target &quot;scan&quot;<br />
Fontconfig warning: &quot;/etc/fonts/conf.d/65-fonts-persian.conf&quot;, line 244: invalid match target &quot;scan&quot;<br />
Fontconfig warning: &quot;/etc/fonts/conf.d/80-delicious.conf&quot;, line 17: invalid match target &quot;scan&quot;<br />
Fontconfig warning: line 73: unknown element &quot;cachedir&quot;<br />
Fontconfig warning: line 74: unknown element &quot;cachedir&quot;<br />

This is actually where I need your help. Does anybody have any ideas? My thought is that symbolic colors were introduced in GTK+2.10 and the mysql-query-browser doesn’t expect symbolic colors, so it throws an error message and messes everything up. However, I wonder if it doesn’t matter since it’s only the appearance of the window. This shouldn’t cause the program to stop working. Maybe it has something to do with the font warnings? But wait, when have warnings ever stopped a program from running?

Anyways, if anybody out there can offer some advice, it would be much appreciated by myself and readers (I’m sure).  If it’s just not going to be possible, I’ll remove this post from the blog to avoid confusion (I’m sure it’s already caused quite a bit).

Source: http://dev.mysql.com/doc/query-browser/en/install-generic-tarball.html
Full list of downloads/mirrors: http://dev.mysql.com/get/Downloads/MySQLGUITools/mysql-gui-tools-5.0r12-linux-i386.tar.gz/from/pick#mirrors
Note: If ‘wget’ is not available on your system, install it with ‘yum install -y wget’ or use ‘curl url -o filename’ instead.

26
Jul

Tools Worth a Gander: expect and pexpect

For those of you interested in programming a dialogue (simulating user actions) for an interactive program take a look at expect (pexpect if you’re into python). The tools are useful if you’re in an environment that needs a lot of test automation. Here’s an article that goes into a bit more detail:
http://www.noah.org/wiki/Pexpect#Description_of_Pexpect

29
Mar

Distribute Program Compilation Over Several Machines on a Network

I just learned about a couple little jewels of applications today which help you compile your large programs faster by distributing them over several different computers on the network. The tools are called distcc and icecream. Here’s a blurb from their man pages:

distcc
distcc distributes compilation of C code across several machines on a network. distcc should always generate the same results as a local compile, is simple to install and use, and is often much faster than a local compile.

icecream
Icecream is created by SUSE and is based on ideas and code by distcc. Like distcc it takes compile jobs from your (KDE) build and distributes it to remote machines allowing a parallel build on several machines you’ve got. But unlike distcc Icecream uses a central server that schedules the compile jobs to the fastest free server and is as this dynamic. This advantage pays off mostly for shared computers, if you’re the only user on x machines, you have full control over them anyway.

More information can be found here:
http://linuxreviews.org/man/distcc/
http://code.google.com/p/distcc/
http://en.opensuse.org/Icecream