Archive for 2007

Shared Libraries Used by and Executable

Saturday, October 13th, 2007

A common problem for people is running an executable and having it fail because it cannot find some shared library need for the executable. The best way to make sure that an executable has access to all the shared libraries it needs is the ldd command. Just run it:

terry@c103:~$ ldd /bin/bash
linux-gate.so.1 => (0xffffe000)
libncurses.so.5 => /lib/libncurses.so.5 (0xb7f07000)
libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7f03000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7dc1000)
/lib/ld-linux.so.2 (0xb7f59000)
terry@c103:~$

If any of the libraries are not found, they will show up as missing. Use the LD_LIBRARY_PATH environment variable to add in the path to the missing libraries.
terry@c103:~$ export LD_LIBRARY_PATH=~/lib
terry@c103:~$ env | grep LD
LD_LIBRARY_PATH=/home/terry/lib
terry@c103:~$

sox audio converter

Monday, August 27th, 2007

The sox program is a nice simple utility for converting audio data files from one format to another. After conversion, you can use many different audio editing utilities to modify the sound and use sox to convert the sound file back to your desired format. Using this for a telephony application, you have a wav file you have edited and you want to convert it back to 1 channel of 8000 samples/sec 16bit raw audio data:

sox -t wav recv0.wav -c 1 -r 8000 -s -w recv0.raw

The sox program is available under Ubuntu as an optional package. Adobe has a nice audio editing utility, but there are some good free ones as well. Two that I’ve used include Audacity and there is an audio studio program on Sourceforge. The audio studio program is a front end for sox and very simple, but it does the job for simple work.

Redhat, /etc/rc and /etc/init.d: chkconfig and service

Tuesday, July 17th, 2007

When i get on a Redhat machine, I’m always trying to remember the commands to start and stop services and configure the /etc/rc*.d directories. Supposedly, if you just create your own links or remove your own links, the operating systems can revert your work. You should use the chkconfig command to enable and disable services. For example:

chkconfig mysqld on

The service command can be used to start or stop services.

service mysqld start

instead of the old

/etc/init.d/mysqld start

The service command is not too useful, but the chkconfig command is.

Converting OGG files to MP3 files

Friday, January 26th, 2007

I’ve ripped a bunch of my CDs onto my computer over the years and many of them ore in the open OGG format which doesn’t work with my iPod or Treo. I wrote a simple little script to convert the OGG files to MP3 for my phone. Since Real Player on my phone only seems to support a flat directory structure, I created the file names out of artist and song name. I just mount up the SD card, change directory to it and run the script passing the songs I want to copy on the command like. Using wild cards makes it easy. For example:

cd /media/sdcard ;
ogg2mp3 /home/terry/jukebox/Yeah_Yeah_Yeahs/Show_Your_Bones/*

The script looks like this…

USAGE=false
if [ ! -f "$1" ]
then
echo "Usage $0 sourceFiles ..."
exit 1
fi TMPFILE=/tmp/tmp$$.wav
while [ $# -gt 0 ]
do
ogg123 -d wav -f $TMPFILE "$1"
DIRNAME=`dirname "$1"`
ALBUM=`basename $DIRNAME`
TMP=`dirname $DIRNAME`
ARTIST=`basename $TMP`
MP3FILE=`basename "$1" | sed -e 's/.ogg/.mp3/' | sed -e     's/^[0-9][0-9] - //'`
OUTFILE="${ARTIST}_${MP3FILE}"
echo "-------------$OUTFILE"
lame $TMPFILE "$OUTFILE"
shift
done
rm -f $TMPFILE

Creating a SSL Certificate for Postfix and Others

Tuesday, January 9th, 2007

I’m trying to generate some generic SSL certificate code for Postfix and other products. This is customized for Postfix, but it is easy to change the output files. I’ve put this together to be a cut and paste, just set the environment variables.

keyfile=/etc/ssl/private/smtpd.key
certfile=/etc/ssl/certs/smtpd.crt
pemfile= /etc/ssl/certs/cacert.pem
pass=superSecret
openssl genrsa -des3 -rand /etc/hosts -passout "pass:$pass" -out $keyfile 1024
chmod 600 $keyfile
openssl req -new -passin "pass:$pass" -passout "pass:$pass" -key $keyfile -out /tmp/.server.csr
openssl x509 -req -days 3650 -passin "pass:$pass" -passout "pass:$pass" -in /tmp/.server.csr -signkey $keyfile -out $certfile
openssl rsa -passin "pass:$pass" -in $keyfile -out /tmp/.server.unencrypted
mv -f /tmp/.key.unencrypted $keyfile
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out $pemfile -days 3650

Starting ssh on an Alternate Port

Monday, January 8th, 2007

If you run a server on the Internet and you do any type of security logging, you know people are constantly trying to find vulnerabilities to your site through ssh. You’ll get pages and pages of PAM authentication errors. Avoiding this is not difficult, just change the port your sshd listens on. Modify the Port parameter in /etc/ssh/sshd_conf and run /etc/init.d/ssh restart. When you log into the system, specify the port on the command line with the -p option.

ssh -p 404 www.tiptopsoftwarecompany.com

Logging in to Linux over the Serial Port

Friday, January 5th, 2007

Remember getty? Remember kermit? If you already put a fork in these utilities, think again. They are still useful today if you want to log into your Linux box over the serial port.

The first step is to make sure the serial port is enabled in the BIOS. I’ll often disable the serial port because it is not in use. Once it is enabled, add an entry in the /etc/inittab to start the getty process on your serial port. On Ubuntu, you just need to uncomment out the following:

T0:12345:respawn:/sbin/getty -L ttyS0 9600 vt100

In the event that the machine you are going to be logging in from is another Linux box, kermit makes a good choice to do the logging in. The rate can probably be set higher than 9600, but it works. To get back to the kermit prompt, type the escape character is ctrl-\ followed by a C. This will get you back to the kermit prompt. You can type connect to return.

-bash-3.00$ kermit -b 9600 -l /dev/ttyb
C-Kermit 8.0.211, 10 Apr 2004, for NetBSD 1.6
Copyright (C) 1985, 2004,
Trustees of Columbia University in the City of New York.
Type ? or HELP for help.
(/u1/terry/) C-Kermit>set carrier-watch off
(/u1/terry/) C-Kermit>connect
Connecting to /dev/ttyb, speed 9600
Escape character: Ctrl- (ASCII 28, FS): enabled
Type the escape character followed by C to get back,
or followed by ? to see other options.
----------------------------------------------------

Ubuntu 6.06.1 LTS m715.tiptopsoftwarecompany.com ttyS0

m715.tiptopsoftwarecompany.com login:

Useful tcpdump command to see traffic on a network

Wednesday, January 3rd, 2007

A useful tcpdump command is the following:

tcpdump port 554 -xX -s 0 -l | tee tcpdump.out

When you want to see the specific messages of a protocol, in this case RTSP running on default port 554, this command shows you the output in “human” readable form.

The -s 0 shows the whole packet. The -x also shows the packet in hex.