Saturday 4 September 2010

Cygwin? Hold on...

I know I had promised in my last post about Cygwin and basically show you how this would work. However due to me not quite getting it just right for you guys I thought I would throw you a little piece of something in the meantime.

C# is also my fave tool for various reasons. Especially the Visual C# Express Edition by Microsoft that has made things easier for almost anyone to code.

The flip side is I now miss using the Borland (Embarcadero) Tools that were around. Microsoft has really taken this RAD methodology far by finally realising that this was how to get people enthusiastic.

Anyway one of the questions that most IT Admin's would love to do is make their jobs easier. If you know programming then it becomes even more easier, however what do you do if you have a tool that does a job and you want to write another tool that you don't want other administrators messing up by accident.

Well sometimes wrapping things in a executable helps. But how do you run an executable that is OS specific in C#?

Well meet System.Diagnostics

It has a class there called Process.

This allows you to define a way of running an external application without finding out a way of writing a interface and things.

So how would this look?

Well people here is a simple example given below that will launch notepad using just a few lines of code.

using System;
using System.Diagnostics;

namespace RunNotepad
{
    class Program
    {
        static void Main(string[] args)
        {

            // Define an object called p which will create our process.
            Process p = new Process();

            // Define the application that you want to run. Don't forget to escape the '\' as these are special.
            p.StartInfo.FileName = "C:\\windows\\notepad.exe";

            // Start the process to run.
            p.Start();
        }
    }
}

Thursday 2 September 2010

Cygwin

So the tool I was mentioning is Cygwin.

A very useful tool for you Linux heads out there. Also very useful to the Windows System Admin especially when trying to fix QoS issues with VoIP phone software as the ping application for Linux is a lot better at times than the built in windows one.

I will show how to use this very useful app in my next post but it goes a long way in making your life a lot easier as you begin to work smarter not harder.

So the next post will take you down why it is better than say having a VM on your machine at times.

Monday 23 August 2010

Out with the old...

and in with the new as they say...


So the blog has a bit of a design transformation. Surprising as this may sound change is good. So here we have a bit of a change to ring in the changes that seem to be happening all the time.

Anyway my next entry to follow is a nice piece of kit which should make you happy when you get stuck wondering now how the hell do I get it to work. This is more so for the Linux lot out there and if anyone says the word Virtualisation then you got it wrong my friend.

I have been known to be quite fond of food particularly of a confectionery kind that works wonders in keeping me in a good mood as well as technically making I hope a lot of you a little bit more happy out there.

So watch this space, Oh and if you happen to be a little bit curious like my cat the tool starts with the letter 'C'.

Catch you around people.....

Sunday 18 July 2010

Two posts in one day!

So two posts on a single day... that's a first!

well for me anyway!

It is amazing how many people you meet in IT who seem to forget that the business of IT is business. It is even more amazing how many businesses seem to forget that IT is the business.

Not understanding me?

Well look at a typical organisation (Sorry my American friends, English English spellings...).

Find out how the IT Structure is set up. You will find that in most organisations IT reports into the Finance function of the organisation.

So when you see this you wonder why is that as IT as a function is separate just as HR or Finance is.

Then when you see things you realise that Business considers IT an cost to the business rather than a cost reduction center.

The reason for living for IT is that it enables the business to function at its most optimum and tries to ensure that the business can function and operate in a complicated environment of rules and regulations across borders.

If modern day computer systems were not maintained and the IT organisation not empowered to act independently what you end up with is that the people best placed to look at things and identify issues are effectively shackled from what is a duty to report and enable the business to operate in.

The problem is in dispelling this myth as this has become quite entrenched due to how the IT industry began.

It had initially begun as a function to finance however over time it has grown much more beyond its original scope to the point now that it attracts talent from a varied disciplines and skill sets.

Organisations are now beginning to recognise this and so are IT decision makers to the point now that you are starting to see IT to be a business function in it's own right and move beyond it being considered as a pure cost.

I am a Windows Admin and I am scared of Linux! Part Deux!

Ok so the title is a bit of a homage to the Hot Shots series of films but seriously as a windows admin you are wondering how do I copy that data from say a damaged partition to say and external USB device like a hard disk.

So remember how we mounted the damaged partition using

ntfs-3g /dev/sda1 /mnt/myrecovery

Well same thing here you need to create a folder to mount your external hard drive to.

So for example I am going to create a directory called external

mkdir /mnt/external

and I am now going to mount my external hard drive to it.

ntfs-3g /dev/sdb1 /mnt/external

So now hoping all goes well you should now have your external hard drive mounted.

So lets begin by copying the entire contents of your failed hard disk.

first lets create a new directory on the external hard drive as say i have some important data on there I dont want to mix. I am going to create a folder called recovery.

mkdir /mnt/external/recovery

So now that I have this set up, I am now going to copy my entire partition to this new folder.

so first I am going to switch to the damaged partition we mounted called myrecovery.

cd /mnt/myrecovery

Once you have switched to here just need to copy the data off to the external hard drive.

cp -Rvf * /mnt/external/recovery

The options -Rvf means

v - verbose show information while copying
f - force and dont prompt
R - copy recursively (similar to the windows xcopy /E option)

rather than using *.* we are using the Linux * wild card which will cover everything including links.

If all everything goes well you should now have copied all your data successfully without any major hiccups.

Well done Windows Admin! You have navigated your way through the Linux command line.

Oh if you are wondering how to come out of the linux system just type in reboot when done and don't forget to take the cd out when booting up. You can then check the hard disk and do what ever is required to restore the data.

To Linux Admins ok... so you knew how to do this already but windows is still very easy to work with.

Sunday 20 June 2010

I am a Windows Admin and I am scared of Linux!

and the opposite of that is I am a Linux Administrator and I think Windows is really rubbish so I wont bother with it.

There above lies the problem!

For a lot of Windows Admins anything involving the command line is scary territory. That is best not ventured.

For a lot of Linux Admins it is a case of "It is a poor ill cousin that doesn't need knowing".

Both views may seem fine in the spheres you work in but here is a important statistic.

Linux will not quite gain universal popularity with users because it is not a user friendly system. People are used to Windows and its error messages because they have been with it for a good part of 20 years or more.

For windows Admins Linux is getting involved more and more in operations to the point where they have to now take note. Be it running things like VMs on VMWare's excellent ESXi environment or for the useful tools that it can bring for those rainy days!

It is time for System Admins whatever system they run to become OS neutral!

There you go shocking statement done but there are reasons why as a Windows Admin it is important to be comfortable with Linux. I will get to the Linux Admins in a moment...

Linux has some very useful tools and I am in this case referring to the many Live CD versions of it like Knoppix, Slackware and my personal favorite System Rescue CD.

The NTFS driver provided with Linux is actually better at handling errors than Windows. Don't believe me? Well take a hard disk that you have had Windows Setup to see the Partition and mount it using a Linux live distribution and guess what? Your Data is there!!!!

Yea alright but how do I mount the thing if I only know GUI and not command line.

First of all people using Monad the old name for PowerShell will find things slightly more comfortable. But if you have somehow managed to be a Windows Admin and never found your way to the command prompt then let me explain something of Linux for you.

Linux treats all devices as files!

Still don't get it then let me say this again...

Linux treats all devices as Files!


So this means that there is a file for a hard disk, a file for a cd-rom, a file for a usb key, a file for a printer...

If you still can't get your head around this then let me say that windows also can treat a device as a file. Look at Mount points for mounting a hard disk and you will understand a little better.

So if you have a hard disk on a Linux system that you need to mount, the Hard Disk would have been stored as a file called something like /dev/sda1 or /dev/hda1 depending on whether you are using SATA or IDE connectors.

So great but how does that help me recover my data.

Well you will need to mount it.

First create a directory this should seem familiar except for the '\' which in Linux is always '/'

So in this example I will create a directory called /mnt/myrecovery

mkdir /mnt/myrecovery


Was the above simple?

Well it gets more simple. You remember that all devices are files? Well we will now "mount" the device to a folder. So I am going to assume you are on a modern machine and there is only a single hard drive attached to it.

So here is the command:

ntfs-3g /dev/sda1 /mnt/myrecovery

and that is it.

So now if you browse in the directory by doing

cd /mnt/myrecovery

and viewing the files which is the command ls rather than dir

You should see your entire data on the Disk!

So the next question is how do I copy the data off...

Well wait for the next post...It will arrive shortly.

Saturday 27 March 2010

Who needs help with the Haddock!

Hello it's your friendly neighbourhood techhie again!
Well a passionate one at any rate.
So one of the issues which I am sure everyone who is a sys admin on AD hits at some point scripting in their life is that darn long LDAP address you need to modify objects.
Remind you of how annoying it is to take that entire object string from the AD Object in AD Users and Computers (or as I lovingly call it ADUC pron: Haddock without the 'H')
Well here is a tool you can write very simply using the wonderful Visual C# Express Edition 2009.
Now before you all go arrrrgggghhhhh progamming or the other word argh another programming language. Everyone just take a deep breath and quote the words from the "Hitchhikers Guide to the Galaxy." which is "Don't Panic!"
First things first, download and install the Visual C# Express Edition 2008 from the Microsoft site. Install it with all the typical settings.
Once this is done create a new project using Windows Form Application template and give it a name something like AD2LDAP.

This form will need two text boxes and two command buttons.
One of the Text boxes will be called Username where you will enter the username of the user.
The second Text Box will be called LDAPPathText which will display the full path of the user using the standard LDAP display format.

Now to start searching the Active Directory you need to add a reference to the DirectoryServices Assembly. You do this by clicking on Project...Add Reference.
So now you now have a form To look something like this. I have added some niceties to this like some labels but the application should work as long as you have the components listed above.
We now need to confirm that the “System.DirectoryServices” assembly has been added to the form for it to use the searching abilities.
You can do this by looking at the associated cs file for the form. The easiest way is to double click on any of the buttons we have on the form.
What you should see is the source code associated with the form.
Over here at the top you can see the line
using System.DirectoryServices;

This basically states that the Directory Services Assembly is now available for use in this application. If you do not see it there just go ahead and type it.
Now what we are going to do is to create a generic search function which checks if the object exists in the local Active Directory. We will call this function IsExistInAD which will return a boolen response (i.e yes or no, true or false) where it will take an normal string argument (i.e. a word, sentence, etc) and search for it in the local Active Directory structure and say yes it exists or no it doesn’t.
What I will show you a sample code here and then explain it in detail.
bool IsExistInAD(string loginName)
{
DirectorySearcher search = new DirectorySearcher();
search.Filter = String.Format("(SAMAccountName={0})", loginName);
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();

if (result == null)
{
return false;
}

return true;
}

What you have to do is create a DirectorySearcher Component called search which will have all the characteristics and attributes of a DirectorySearcher component.
DirectorySearcher search = new DirectorySearcher();

We will then set it up to search for only the username object in Active Directory.
search.Filter = String.Format("(SAMAccountName={0})", loginName);
Out of it we only want it to return the canonical name (“cn”) of the object which in other words is the LDAP string we are after.
search.PropertiesToLoad.Add("cn");
We will then use the search function to locate the username and see if it exists in the current domain an return the result to an object of type SearchResult.
SearchResult result = search.FindOne();
We shall now see if the result of this has been successful in finding the canonical name of this user. If it hasn’t been successful then the SearchResult object result should be empty. If it is empty then the user has not been found so we can return a false result to say the user doesn’t exist.
if (result == null)
{
return false;
}

Otherwise in all other instances we can return the user exists.
return true;

So this allows us to test to see if the user exists in AD.
Let us now look at how we locate the LDAP path for the user using one of the buttons.
private void button1_Click(object sender, EventArgs e)
{

if (UserName.Text.Length > 0)
{
if (!IsExistInAD(UserName.Text.ToString()))
{
UserName.ForeColor = System.Drawing.Color.Red;
MessageBox.Show("User Not Found! Please enter the exact username of the user. ", "User Check");
}
else
{
UserName.ForeColor = System.Drawing.Color.Blue;
DirectorySearcher search = new DirectorySearcher();
search.Filter = String.Format("(SAMAccountName={0})", UserName.Text.ToString());
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
LDAPPathText.Text = result.Path.ToString();
}
}
else
{
MessageBox.Show("User Name not Entered! Please enter the exact username of the user. ", "User Check");
}
}

As before in the function to check if the user exists in AD we use the same method however we use the generic function IsExistInAD to check if the user exists before we continue to return LDAP Path in one of our text boxes to use.
if (!IsExistInAD(UserName.Text.ToString()))
{
UserName.ForeColor = System.Drawing.Color.Red;
MessageBox.Show("User Not Found! Please enter the exact username of the user. ", "User Check");
}

So in general what we want is for the application to return a error message if the user doesn’t exist and to validate for conditions when nothing is entered in the username text box and all other conditions before we perform the search.
So this is a simple form of searching for users. Of course this is not what you might call very secure in the sense of handling usernames and passwords, defining the domain to search etc. But it is a good platform to start writing your own applications using the power of Active Directory and c#

Here is the source code in case you need it.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.DirectoryServices;


namespace ADtoLDAP
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

bool IsExistInAD(string loginName)
{
DirectorySearcher search = new DirectorySearcher();
search.Filter = String.Format("(SAMAccountName={0})", loginName);
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();

if (result == null)
{
return false;
}

return true;
}


private void button1_Click(object sender, EventArgs e)
{

if (UserName.Text.Length > 0)
{
if (!IsExistInAD(UserName.Text.ToString()))
{
UserName.ForeColor = System.Drawing.Color.Red;
MessageBox.Show("User Not Found! Please enter the exact username of the user. ", "User Check");
}
else
{
UserName.ForeColor = System.Drawing.Color.Blue;
DirectorySearcher search = new DirectorySearcher();
search.Filter = String.Format("(SAMAccountName={0})", UserName.Text.ToString());
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
LDAPPathText.Text = result.Path.ToString();
}
}
else
{
MessageBox.Show("User Name not Entered! Please enter the exact username of the user. ", "User Check");
}
}


private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}

Sunday 7 March 2010

Where are you from?

This is a question that most people get asked at some point in their lives. The context they get asked however can be quite varying...

Ranging from local Chav's asking the question near a job centre followed in the same sentence by the usual statement "Go Home Paki!" to the more curious question trying to understand where you got here.

There used to be a time when those words "Go Home Paki!" used to hurt but then the more I thought about it the more I laugh...because seriously for me to do that I would have to go back in time to when my ancestors left Baluchistan several hundred or even millennia before. If anything I am sufficiently glad that they ask the question "Where are you from?" it shows that in their world things have moved on just a tad bit!

So moving on I came across this article in the Guardian this morning and immediately got thinking hmm how would I explain my history and how I got here...

Well bear with me a bit and also since a lot of this has been lost through the mists of time it may not be a fact the same as it might not all be fiction.

So my ancestors basically to escape a God in Human form who took to not liking the particular caste my ancestors belonged to went on a huge killing spree! To escape from this God who was on a killing spree my ancestors sought refuge from a local goddess in a temple who said she will protect my ancestors if they give up the sword for a needle and thread. Still with me so far?

If not then here is the long version of it here.

Somewhere along the way the descendants of my ancestors in what is now Modern Day Pakistan ended up joining the rulers of the new Maratha Confederacy whose aim was to oust the Mughal Empire and establish a separate state from all external influence. Well lets just say that but for a brief period of time this meritocracy didn't quite work out and eventually people got scattered all over Pre 1947 India.

Some time during this my ancestors had settled down south and basically hung about as things were better or they got bored moving or whatever their reasons were they got integrated with the local culture and hey presto it leads to me and my parents where the gene that makes us want to move got activated again and hey presto here I am.

So really it gets really complicated when some chav decides to tell me "Go Home Paki" as it would mean me travelling through time and space for me to reach a physical location but then the State of Pakistan did not actually exist in that time so how can I?

Tuesday 2 March 2010

Aaromale Lyrics

Ok A huge diversion. A.R.Rahman has released some really good music for the film Vinnaithandi Varuvaiya (Tamil - 2010)

A particular tune has been stuck in my head for like a very long time now so I thought I would share the lyrics. Very nice song in the Malayalam Language!

The Lyrics are here now (Thanks Rajmohan Kanthaswamy & Vijay Ganesh Subramanian for the lyrics and translation)
Listen here: http://www.tunewiki.com/lyrics/alphons-joseph/aaromale-s2118982.aspx
Also remember that things may sound strange or as I like to call it get lost in translation. For the moment enjoy this superb tune!

Mamalayeri Varum Thennal
(A gentle breeze, blowing in through the mountains.)
Puthu Manavalan Thennal, ...
( A tender breeze, decked up like a bridegroom)
Palli Medaye Thottu Thalodi Kurushil Thozhuthu Varumbol,
(When it arrives after worshipping the cross at the altar..)
Varavelpinu MalayalaKara Manasammatham Choriyum,
( This land of Kerala will grant permission for a warm welcome )

Aaromalae, Aaromalae, Aaromalae, Aaromalae....
(O Beloved....O Beloved...O Beloved.....O Beloved...)

Swasthi Swasthi Su Muhurtham,
( Auspicious is this solemn occasion )
Sumungali Bhava, Manavatti
(O Bride, may you be blessed with a long wedded life)
Swasthi Swasthi Su Muhurtham,
( Auspicious is this solemn occasion )
Sumungali Bhava Manavatti
(O Bride, May you be blessed with a long wedded life)

Shyama Rathri Than Aramanayil,
( In the inner sanctum of the dark night )
Mari Nilkayo Tharakame,
( O Star..why are you staying away ? )
Pulari Manjillae Kathiroliyay,
( Like a ray of light in the morning mist,)
Akalae Nilkayo Penmaname,
( Are you standing afar, O Lady ? )

Chanju Nilkuma Chillayil Nee, Chila Chilambiyo Poonkuyilae
(On the leaning bough, O Cuckoo bird, did you sing so sweetly ? )
Manchiragile, Marayoliyae Thediyathiyo Poorangal
(Did the festivities arrive in search of the earthern lamp's flame ?)

Swasthi Swasthi Su Muhurtham,
( Auspicious is this solemn occasion )
Sumungali Bhava Manavatti
(O Bride, May you be blessed with a long wedded life)

Aaromalae... Aaromalae....
(O Beloved....O Beloved....)


Kadalinu Karayodiniyum Padan Sneham Undo ?
(Does the sea still possess the love to serenade the shore ?)
Mezhukuthurikalayi Urukan Iniyum Pranayam Manasil Undo ?
(Is there still love in the mind..to be melted like candle wax ?)

Aaromalae.. Aaromalaeee.. Aaromalaee
(O Beloved....O Beloved...O Beloved.....O Beloved...)
Aaromalae.. Ohh.. Ho ! - (O Beloved....)

Sunday 14 February 2010

Has it really been that long??

Well has it really been 2 years since I posted anything...To quote Victor Meldrew "I don't believe it!".

It is safe to say that I haven't got one foot in the grave though it may sometimes feel like it. But far from it I have been busy over the last two years in what is generally known as "ducking and dodging" the travails of the modern IT world that it is.

In the time I have been away we have had the iPhone 3GS (Useless), Windows 7 (Faster than a speeding bullet and XP), Nokia n97 (Everyone seems to own a variant of this) and the spectacular(ily bad) iPad.

All in all not bad!

So my resolution for this year of the tiger (It is the Chinese New Year today after all) is to post here more often and explain the intricacies and mind boggling explanations to the simplest things that have always confounded you!!!

Looking forward to the year ahead!