msgbartop
A cronological documentation test project, nothing serious, really!
msgbarbottom

19 Jan 2010 Change ethernet settings using ethtool

Force network speed on a network card to 100 MBit Full Duplex and in the same time disable auto negotiation

# ethtool -s eth0 speed 100 duplex full autoneg off

These settings are active until you reboot the machine or restart the network.

In order to keep this change on each system reboot, append the following line in the following Redhat file /etc/sysconfig/network-scripts/ifcfg-eth0

ETHTOOL_OPTS="speed 100 duplex full autoneg off"

An alternative tool to use to change the settings is mii-tool.

Tags: ,

Posted by Hans-Henry Jakobsen

17 Nov 2009 Create a temporary “Site Down” notice in Apache

This post describes how to make a “Site down for maintenance” notice using Apache .htaccess and the mod_rewrite module.
I assume you know how to enable the Apache htaccess directive and the mod_rewrite module.

First you need to create a .htaccess file in your root level of your website.
Next you add the following lines to it

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !/sitedown.html$
RewriteRule $ /sitedown.html [R=302,L] 

The .htaccess file should be “active” immediately and you should see the content of your sitedown.html file. If not, try clearing your browsers cache.

If you as a maintenance user would like to access the site without seeing the sitedown.html file, add the following line to enable IP address exception

RewriteCond %{REMOTE_HOST} !^192\.168\.0\.12
 

Remember to replace the IP address with your address.

The .htaccess file should now look something like this.

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !/sitedown.html$
RewriteCond %{REMOTE_HOST} !^192\.168\.0\.12
RewriteRule $ /sitedown.html [R=302,L] 

Just delete the .htaccess file when you are done with your maintenance and your site will be available again.

Tags: ,

Posted by Hans-Henry Jakobsen

17 Nov 2009 Zimbra distribution list commands

This is just a short post describing Zimbra distribution list (mailinglist) commands.

These commands should be run as the zimbra user

# su - zimbra

List all distribution lists

# zmprov gadl

Print only members addresses of a distribution list

# zmprov gdl mailinglist@example.com | grep zimbraMailForwardingAddress: | awk {'print $2'}

Show if a list is member of another distribution list(s)

# zmprov gdlm mailinglist@example.com

Tags: ,

Posted by Hans-Henry Jakobsen

02 Nov 2009 Howto backup mysql stored functions and stored procedures

This is how you can backup you MySQL database(s) and stored procedures

# mysqldump --routines <dbname>

Or you can backup only the stored procedures

# mysqldump --no-create-db --no-create-info --no-data --routines <dbname>

Tags: , , ,

Posted by Hans-Henry Jakobsen

23 Oct 2009 mysql alternative to PHP substr_count function

The substr_count function in PHP counts the number of substring occurrences. This post describes how to create a mysql stored function to behave just like PHP’s substr_count function.

This function can be created from your mysql console

delimiter ||
DROP FUNCTION IF EXISTS substrCount||
CREATE FUNCTION substrCount(s VARCHAR(255), ss VARCHAR(255)) RETURNS TINYINT(3) UNSIGNED LANGUAGE SQL NOT DETERMINISTIC READS SQL DATA
BEGIN
DECLARE count TINYINT(3) UNSIGNED;
DECLARE offset TINYINT(3) UNSIGNED;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET s = NULL;

SET count = 0;
SET offset = 1;

REPEAT
IF NOT ISNULL(s) AND offset > 0 THEN
SET offset = LOCATE(ss, s, offset);
IF offset > 0 THEN
SET count = count + 1;
SET offset = offset + 1;
END IF;
END IF;
UNTIL ISNULL(s) OR offset = 0 END REPEAT;

RETURN count;
END;

||

delimiter ;

Usage

Example 1

SELECT substrCount('/this/is/a/path', '/') `count`;

`count` would return 4 in this case. Can be used in such cases where you might want to find the “depth” of a path, or for many other uses.
This function is great to count the content of mysql ENUM and SET field data types.

Example 2

SELECT substrcount(
                `tablename` , ','
        ) as tablename
        FROM `tablename`
        where substrcount(
                `tablename` , ','
        ); 

The content of table named tablename is a comma separated list generated from mysql ENUM datatype

2000/2001,2001/2002,2002/2003,2003/2004,2004/2005,2005/2006,2006/2007,2007/2008,2008/2009,2009/2010

In Example 2 the result from this query would be 9, telling us that there are 9 commas in this tablerow.

Source: Posted by Andrew Hanna on August 24 2006 8:04pm

Tags: , , ,

Posted by Hans-Henry Jakobsen