The Sysadmins

Tips and tricks from the Sysadmins

Category: Linux

Ubuntu Server – Connect to MSSQL via PHP

I was asked to look at querying a MSSQL database from an Ubuntu server. After some digging, bad information and trial & error it turned out to be very straight forward.

This has been tested on Ubuntu 8.10 and Microsoft SQL Server 2000/2008.

From the Ubuntu server

sudo apt-get install php5-sybase php5-odbc freetds-common

Configure /etc/freetds/freetds.conf, edit the entry at the bottom to point to your SQL server.

Ubuntu Freetds Conf

Test connection to the MSSQL server with this PHP script


$server = 'servername';
$username = 'sa';
$password = 'password';
$database = 'xxx';
$connection = mssql_connect($server, $username, $password);

if($connection != FALSE)
echo "Connected to the database server OK<br />";
die("Couldn't connect");

if(mssql_select_db($database, $connection))
echo "Selected $database ok<br />";
die('Failed to select DB');

$query_result = mssql_query('SELECT @@VERSION');
$row = mssql_fetch_array($query_result);

if($row != FALSE)
echo "Version is {$row[0]}<br />";

You can browse to the location of the PHP via your browser, or run php filenameyouchose.php from the cli. This should return the version of the SQL server and give you confirmation that it worked.

Connected To MSSQL

VMware vSphere Web Client Console on Ubuntu Linux 11.04

I was interested to play with the new Web Client and to see how well it works on something like Ubuntu. Being able to manage ESXi/Vcenter from a non-windows machine is a pretty big deal!

So… with an Ubuntu 11.04 Desktop live CD in hand and Vcenter 5 configured I thought I’d have a go.

First off, browse to your Web Client install, by default this is https://ip:9443/vsphere-client/



The web client requires Adobe flash to operate, go ahead and install it







This brings us to the login page, you can see in the bottom left that the Client integration plug-in is not currently installed. This provides functionality for the web console. Click the link and download the .bundle which is around 42MB





To install this head to the terminal and run sudo sh ./VMware-VMRC.i386.bundle and agree to the defaults







Now head back to the login page and login. From here you can do a large array of tasks, for example; stop and start guests, take snapshots, editing a guest configuration, clone, migrate, view events and view performance graphs to name a few. I’ve linked a site at the bottom of this post which gives you a good walk through of features. To access the console, select the guest you want to view, and select ‘Launch Console’



Select Launch Console which will open the console in another tab/window



I have some issues with one of my 2008 R2 guests which won’t detect or move the mouse (haven’t resolved this yet), but the others are working well, even in full screen mode.

Other functionality seems great, here’s a good walk through of the interface:

Walk through of new vSphere 5 web client interface –

A Brief Introduction to Using Zsh for Systems Administration


Zsh is a Unix interactive shell with built-in scripting language that’s particularly suitable for administration of Unix and Unix-like systems. The shell is bash-like in a number of ways, making it easy to get started with for newcomers, and the scripting language has a clean syntax and powerful features that let you take control of local and remote systems alike without the language getting in your way.

In particular the string expansion, file and directory globbing and clean syntax for iterating over lists make it a good fit for systems scripting and control of multiple machines. It comes already installed in a vast number of popular Linux and BSD-based distributions, including Apple OS X. If you find it’s not installed then it’s usually just a quick package management command away.

Being bash-like, many simple bash scripts will run without issue via zsh, and those that don’t usually only require a minimal porting effort. Scripting from scratch is where its power lies though, and we’ll get into that quite a bit in this article series.

On top of the powerful scripting language and bash similarities, the interactive shell has one compelling feature for systems administrators: multi-line, multi-area prompts. Prompts in zsh, with a minimum of configuration, can reside on the left and right of the screen and span multiple lines. With full control over colours and support for syntax highlighting, zsh gives you a truly useful prompt that’s trivially context-aware, giving you at-a-glance information about the running environment you find yourself in.

If you have a multitude of systems to look after you can configure the prompt to make it acutely aware what machine you’re on, which user you currently are, and whereabouts in the directory hierarchy you find yourself. If you’ve configured it properly, issuing ‘pwd’, ‘whoami’ or ‘hostname’ should be a thing of the past.

Lastly, it’s easy to configure and there’s a wealth of information online, so learning more about zsh and its power, as you get to know it, is easy and fun. Let’s get stuck in with the scripting language with a view to working with multiple machines over SSH, and we’ll cover the prompt in a followup article.

This article assumes some familiarity with shell scripting and basic shell operation.
Continue reading

Using Stunnel to Encrypt Unsecure Connections

So you’re a fully signed up ‘tin foil hatter’ and you have an old app that communicates over the internet but doesn’t use SSL?

Not to worry, there is a solution for you and its called stunnel.

Stunnel is available for both Linux and Windows, and simply put creates an SSL tunnel from one machine or server to another.

So why use stunnel? Well stunnel…

… provides an extra layer of security to an internet based application.
… secures data previously transmitted in plain text.
… protects your exploitable services by hiding them behind stunnel.

So what else can it be used for? Well…

… you could use it to fool certain websites into thinking you are in a different location.
… it can be used as a simple ‘bouncer’ for pretty much anything!

Continue reading