Adding cookie information to apache log files

The typical apache combined log format configuration is :

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

But by appending a simple element, %{Cookie}i, one can record cookie information into the logfile:

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{Cookie}i\"" combined-cookie

${Cookie}i will insert the contents of the HTTP Cookie request header as received by apache.

Notice that I renamed the logformat from combined to combined-cookie.
You have to then update any sections in the apache config that use the combined reference to use combined-cookie.

Perl regex one liner howto

$perl -p -i -e 's/goonies/gremlins/g' monsters.txt

The -p indicates that the substitution be done for every line in monsters.txt.

The -i causes changes to be written in place.

The -e indicates that the stuff in between '' is the program to execute.

Using mysqldump to create a csv file

$mysqldump -u user -p --fields-terminated-by=',' --tab=/tmp mydatabase mytable

The above command will create 2 files in /tmp. mytable.sql and mytable.txt. The sql file will contain the table creation schema and the txt file will contain the records of the mytable table with fields delimited by a comma.

Keep in mind that the --tab option will only work if the mysql client and the mysql server are all running on the same machine.

You can omit the 'mytable' part of the command to export all tables in the database, one table per file.

Using xargs to create sql statements

I often need to create sql queries or updates based on data from flat files. For example, given the text file emails.txt that contain email addresses, I want to issue multiple select statements to look up the first and last name of the person identified by the email address.

Assume the emails.txt's content is:

friend1@friendlyemaildotcom
friend2@friendlieremaildotnet
relative@familyemaildotnet

Simple examples of dig, the dns utility

To get an A record for an address:

$dig www.crumpeta.com

To get any record for an address:

$dig www.crumpeta.com ANY

To use a specifig dns server:

$dig @ns.crumpeta.com www.crumpeta.com

To find the MX records of a domain:

$dig crumpeta.com MX

Apache custom directory layout

Apache 1.3 can be configured to use a custom directory layout. The following example shows how one can configure, compile and install apache under the /opt directory.

Configuration

Issue the following call on the command line from the apache src directory:

#./configure --prefix=/opt/apache --exec-prefix=/opt/apache

The prefix option specifies where apache is installed. Key directories that are placed by default in the directory defined by prefix are conf and log.

The exec-prefix options specifies where the executable
files are installed. In the example above, they will be installed in a subdirectory bin under the /opt/apache directory.

To preview the installation layout issue:

#./configure --prefix=/opt/apache --exec-prefix=/opt/apache --show-layout

About this site

I am an independent consultant who specializes in web development projects.

Syndicate content