I can’t live without vi

March 25th, 2011

I really like the vi editor.
Today, after installing a new debian linux host, I issued the visudo command to set up some user permission, but I found the usual dreadful surprise: the default editor was “nano”.
Oh dear! Fastly I went out taping ^X and then I wrote my beloved

export EDITOR=vi

to set “correctly” the environment variable before running again visudo

monitoring a remote webserver with freeshell.de

February 16th, 2011

During this last week a webserver of mine appears to be very slow. This webserver is made by a CMS, so any page is load after making some SQL query to a DB.
Since a wget of a static jpg image has a normal speed, while is not fast as usual to load any page, I convinced myself to monitor the database performances.
I made a simple monitoring by 3 steps.
Step 1: I wrote a php simple page for my webserver to make a db connection, executing a couple of queries and telling me the needed time to get te response. Calling my http://www.mywebsite.org/test.php I’m able to read the result. My php script is

<?php
function diff_microtime($mt_old,$mt_new) {
list($old_usec, $old_sec) = explode(‘ ‘,$mt_old);
list($new_usec, $new_sec) = explode(‘ ‘,$mt_new);
$old_mt = ((float)$old_usec + (float)$old_sec);
$new_mt = ((float)$new_usec + (float)$new_sec);
return $new_mt – $old_mt;
}

$ti=microtime();
echo “STARTING SQL EXECUTION: “. $ti .”<br>”;
$dbhost = ‘localhost’;
$dbuser = ‘mydbusername’;
$dbpass = ‘supersecretpassword’;
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die (‘Error connecting to mysql’);

$dbname = ‘mydatabase’;
mysql_select_db($dbname);

echo ‘TABLE STRUCTURE FOR <i>cms_module_visitorstats</i>:<br>’;
$res = mysql_query(‘DESCRIBE cms_module_visitorstats’);
while($row = mysql_fetch_array($res)) {
echo “{$row[‘Field’]} – {$row[‘Type’]} <br>\n”;
}
$res = mysql_query(‘SELECT count(*) from cms_module_visitorstats;’);
while($row = mysql_fetch_array($res)) {
echo “<br>{$row[0]} Records in <i>cms_module_visitorstats</i><br>”;
}

mysql_close($conn);

$tf=microtime();
echo “ENDOF SQL EXECUTION: “. $tf .”\n<br>\n”;
echo “TIME ELAPSED  “. (1000 * number_format(diff_microtime($ti, $tf), 3) ).” milliseconds”;
?>

Step 2: I wrote a shell script on freeshell.eu in order to call from crontab my php remote script and writing my measures on a log file. My crontab looks like this:

1,11,21,31,41,51 * * * * bin/getdata.sh

and my shell script, is simply:

#!/bin/sh
OUTFILE=”public_html/test/sqlprau.log”
cd
touch $OUTFILE
MILLI=`lynx -dump http://www.mywebsite.org/test.php|grep “TIME ELAPSED” | awk ‘{ print $3}’`
SECON=`date “+%d/%m/%Y %H:%M:%S – %s – “`
echo $SECON $MILLI >> $OUTFILE

Step 3: Thanks to perl and gnuplot programs, getting some help from this manual, I was able to write this simple perl cgi-bin to read the file made in the  step 2 and show a sort of graphic like the following.
Yes, now I’m sure my website appears to be slow.

how my server is slow

forgotten ping

January 24th, 2011

Today I noticed a “forgotten ping” running on a server: 4 millions and half of transmitted packets!
forgotten_ping

compiling bacula-sd 2.4.4 on AIX

January 11th, 2011

Recently I compiled an old release of Bacula on an AIX 5.3 host (oslevel command shows “5.3.0.0” as output), using a gcc 3.3.2 version. My need was to make a bacula-sd binary file. To end my compilation I performed some quick and dirty hack.
First, I downloaded and installed the MySQL includes and client, as a prerequisite:

# rpm -Uvh MySQL-client-3.23.58-2.aix5.1.ppc.rpm MySQL-devel-3.23.58-2.aix5.1.ppc.rpm

after downloading the tar.gz file, I uncompressed and opened it in a temporary directory. Then I moved to the bacula-2.4.4 directory and run the configure command with several options:

./configure -prefix=/usr/local/bacula -enable-largefile -disable-libtool -with-pid-dir=/usr/local/bacula/var/run -with-subsys-dir=/usr/local/bacula/var/run/subsys –disable-conio –enable-build-stored –with-mysql

Then, I opened the Makefile to comment out the line with .PATH variable definition

#.PATH:         .

and I added some line to the ./src/bacula.h file before the pthread.h inclusion:

/* Beginning of the code added by hand */
#define __SIZEOF_PTHREAD_BARRIER_T 20
#define __SIZEOF_PTHREAD_BARRIERATTR_T 4

typedef volatile int pthread_spinlock_t;

typedef union
{
char __size[__SIZEOF_PTHREAD_BARRIER_T];
long int __align;
} pthread_barrier_t;

typedef union
{
char __size[__SIZEOF_PTHREAD_BARRIERATTR_T];
int __align;
} pthread_barrierattr_t;
/* end of the added code, next line was the original one */
#include <pthread.h>

in the file ./src/stored/stored.h I made me sure to include mtio.h in the right place:

//#ifdef HAVE_MTIO_H
//#include <mtio.h>
//#else
//# ifdef HAVE_SYS_MTIO_H
# include <sys/mtio.h>
//# else
//#   ifdef HAVE_SYS_TAPE_H
//#   include <sys/tape.h>
//#   endif
//# endif
//#endif

then in src./lib/bsys.c I commented out the initgroups definition:

/*
#ifdef HAVE_AIX_OS
extern “C” int initgroups(const char *,int);
#endif
*/

finally, as root, I commented out the line 104 of /usr/include/sys/mtio.h file (Yes, I know, It’s an ugly solution)

#ifndef _MTEXTEND_H
/*  #include <sys/mtextend.h> */   /* XXXXX commented in order to compile bacula */
#endif

After making all theese changes, I was able to end the bacula-sd (and other) part of bacula suite.
Before the installation, You may find useful to strip the binary files

# cd ./src/stored
# strip bacula-sd bscan btape bcopy bextract bls
# make install

At this point I tested my bacula-sd starting it in foreground, verbose and debug mode

# /usr/local/bacula/sbin/bacula-sd -v -f -d 516

and I started my backup test.

URL redirection at freeshell.de

November 22nd, 2010

This blog is hosted by freeshell.de – Nic Nac Project server. Great! 🙂

Since the same page of this server can be reached by several URL, I decided to add a little trick for redirecting my blog visitor to the same address. This may be useful to help web spiders in indexing my pages.

For this reason if  You try to reach

http://www.freeshell.de/~jose
http://nic-nac-project.de/~jose
or any other equivalent URL, Your browser will be redirected to
http://www.nic-nac-project.de/~jose/

Since my blog is a WordPress one, a .htaccess file has been made by my software configuration. I set up the redirection by adding two lines to the .htaccess file created by WordPress in my public_html directory:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~jose/
RewriteCond %{HTTP_HOST}    !^www\.nic-nac-project\.de [NC]
RewriteRule ^(.*)$    http://www.nic-nac-project.de/~jose/$1 [L,R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~jose/index.php [L]
</IfModule>

editing the AIX /var/adm/wtmp file

October 25th, 2010

I can’t see any useful reason, but if You like to modify the output of the “last” command on an AIX system, You can convert to an ASCII file the /var/adm/wtmp file, editing it and then rebuild it. E.g.

/usr/sbin/acct/fwtmp < /var/adm/wtmp > /tmp/temp.file
vi /tmp/temp.file
/usr/sbin/acct/fwtmp -ic < /tmp/temp.file > /var/adm/wtmp
rm /tmp/temp.file

compiling clam-av 0.96.3 in an old linux system

September 22nd, 2010

If for some reason You are trying to compile clamav-0.96.3 in an old linux system (e.g. a Debian sarge with a 3.3.5 gcc version) You will get a “compiler too old” error.
I know it is a kludge, but it’s possible to ent the compilation process in two steps.
first, opet the ./clamav-0.96.3/libclamav/c++/configure file and disable the line

as_fn_error “C++ compiler too old (${gxx_version})” “$LINENO” 5

e.g. writing [02].*) instead of [023].*) in the previous line.
second, run the main ./configure script disabling llvm.

./configure –disable-llvm

Then run make and make install as usual.

backup or dump a micro$oft DHCP configuration

August 31st, 2010

On a Microsoft 2003 server It’s possible to backup the DHCP configuration with the command

C:\Documents and Settings\server\Desktop>netsh dhcp server export dumpfilename.netsh all

while If You need a plain text dump (e.g. to plan a migration to a free-software DHCP server)

C:\Documents and Settings\server\Desktop> netsh dhcp server dump all >dumpfilename.txt

Human readers usually like the last way…
dhcp_dump