Category Archives: General

General posts which either can’t be categorised or I didn’t have time to think of a category.

MySQL Workbench SSH private key connection error

I had a problem getting connections to MySQL using TCP/IP over SSH working. I wanted to use a private key instead of saving a password for the SSH connection, but I kept getting an error message:

Authentication error. Please check that your username and password are correct and try again.
Details (Original exception message): Authentication failed, please check credentials.
Please refer to logs for details

The problem was that I was using a PPK file instead of an OpenSSH file. The solution is to open PuttyGen, load your PPK file and convert it to an OpenSSH key.

Problem solved!

Tuning Apache

I was updating the Apache configuration on a new CentOS Linux server today and trying to update the tuning parameters such as MinSpareServers. No matter how many times I changed them and did apachectl restart I couldn’t get them to take affect.

Eventually I remembered that changing these settings requires a stop & start, rather than just a restart!

apachectl stop; apachectl start

Clear scrollback in Putty

When I’m running commands with a lot of output via an SSH shell (I use Putty) I like to have a long buffer and scroll back through the output. However, if I’ve already run a lot of other commands then it’s difficult to see when the output of the last command started. I found a useful printf sequence that can be used to clear the buffer in Putty (can’t remember where I found it I’m afraid…).

vi ~/bin/clearandrun

Enter the script below:

#!/bin/bash
clear && printf '\033[3J';
$*

Then chmod +x ~/bin/clearandrun and you can now precede any command with clearandrun to clear the screen and scrollback before running the command.

Unable to access DFS redirection shares

We had a problem today on our Windows 2008 Server installation where most shares under a DFS namespace were accessible correctly, but all shares which were hosted on a physically different server, using DFS redirection, were unaccessible.

The message the client received was the typical message about being unable to access the share, please check with your system admin, etc., and then at the end said:
“The file cannot be accessed by the system.”

It turned out the solution was simply a case of restarting the DFS Namespace service on the server hosting the namespace. I don’t know why this happened but we had restarted the Windows server hosting DFS a few times recently due to hardware problems so I presume it somehow lost contact with the other server.

What does filter=2 in the querystring mean on Facebook?

I was wondering what filter=2 means when you see it in the query string on a page on Facebook. A quick search on Google didn’t turn anything up either which was annoying as I always feel that you should be able to find an answer to practically any well-worded question on Google!

In the interest of allowing Google to provide an answer to this question I am writing this post:

filter=1 means display only posts by the page
filter=2 means display only posts by others
filter=3 means display highlights (and is also the default if no filter is specified)

Hope that helps someone!

Shape Catcher

Have you ever wanted to put some kind of symbol on a page but didn’t want to have to resort to Photoshop to create an image for it? There are lots of Unicode symbols but trying to find the one you want can be very difficult. I found a really useful website called Shapecatcher which allows you to draw the symbol that you want and it will search for Unicode characters close to the shape you have drawn. Very handy, and it’s amazing some of the characters that exist in Unicode!

qmail log files on Plesk CentOS server

After a big of digging around on a server today, I followed my nose to where the log files are held.

qmail is started from within /etc/init.d/qmail. Searching for qmail-start reveals two ways in which qmail can be started, the Debian way or the “other” way. As this is CentOS we need the “other” way, which is:

qmail-start "$defauldelivery" splogger qmail &

The splogger argument tells qmail to use the syslog for logging, and CentOS uses rsyslog so look in the file /etc/rsyslog.conf. There you will find the line:

mail.*                    -/usr/local/psa/var/log/maillog

which finally leads us to the path to the qmail log file:

/usr/local/psa/var/log/maillog

Phew, got there at last! 🙂

Executable PHP files

I have a PHP script that I will be running in one of three ways:

  • interactively, from the Linux command line
  • as a cron tab, on a Linux box
  • as a web page, with Apache and mod_php

In order to do this I found that I can do the following:

#!/usr/bin/php -q
<?php 
@ob_end_clean();

if (isset($argv)) {
	define("SHELL",true);

	$options = getopt("c");
	if (isset($options['c'])) {
		echo "Running as a cron job ...\n";
		define("INTERACTIVE",false);
	} else {
		echo "Running interactively ...\n";
		define("INTERACTIVE",true);
	}

} else {
	echo "Running via Apache...
";
	define("INTERACTIVE",false);
	define("SHELL",false);
}

The general idea is:

  1. Line 1: tell the Linux shell that the command, when executed directly, should be interpreted by php, and not the shell that you’re running in (“-q” tells PHP to suppress any HTTP headers).
  2. Line 3. If the script is running via Apache then tell it to remove the first line which has already been output. Use the @ to suppress warnings as ob_end_clean isn’t available when running from the CLI.
  3. Use the $argv array to determine if we are running via CLI, it’s not set when run through mod_php
  4. When executed from cron, we will pass a parameter “-c” to indicate it should run in “non-interactive” mode, use getopt to read the parameters and isset to check if the “-c” parameter was passed.
  5. Now, the SHELL and INTERACTIVE constants can be used to determine if we are in a shell or Apache, and interactive or cron-mode, respectively.

Finally, don’t forget to chmod the script to make it executable.

chmod 700 script.php