Tag Archives: linux

bash script to check if a process instance is running

#!/bin/bash
if [ $# -ne 2 ]
then
echo "$0 process_name instances_count"
exit 1
fi

function count_match {
echo Count Match #Your code goes here
}

function count_mismatch {
echo Count Mismatch #Your code goes here
}

process=$1
exp_count=$2

run_count=`ps eax | grep ${process} | grep -v grep | wc -l`

if [ ${exp_count} -eq ${run_count} ]
then
count_match
else
count_mismatch
fi

Please note “grep -v grep” is not be required for cygwin, but even if you retain it, it doesn’t alter the behavior.

Advertisements

How to boot Linux using Windows bootloader (XP)

You want to setup dual boot on your computer but do not want to install Grub or Lilo (You still are use LILO?), then read on….

Otherwise, if you are tired of Windows over writing Grub or LILO every time you setup Windows, then you can sacrifice the powers of Grub and shift to Windows Boot Loader to boot you into Linux.

Here are the steps: (Ideal case)

Windows XP Loader (NT Loader) needs Linux Master Boot Record (MBR) to boot into Linux.

If you can boot into Linux, grab the first 512 bytes of boot sector from the root partition of Linux  where Grub is installed (/dev/sdaN) to an external drive.

 dd if=/dev/sdaN of=grub.bin bs=512 count=1

Here is the twist!

In my case, I had an existing Linux installation but I could not boot into Linux and I didn’t have a rescue disk. I installed Ext2 IFS For Windows and copied MBR which I had extracted previously before I wiped out Grub  /boot/grub/stage1 and named it grub.bin (Your MBR is nothing but stage1 boot-loader used by GRUB).

To setup Windows bootloader to load Linux, we need to add an entry corresponding to Linux.

Boot into Windows. Set appropriate attributes for boot.ini so that it is editable.

attrib -r -w -s c:\boot.ini

Add the following entry to the file boot.ini

 c:\grub.bin="Ubuntu Linux 7.10"

Restart the machine and Windows XP boot loader shows Ubuntu Linux 7.10 as one of the options.

Select this option and viola! you should see Linux booting 🙂

For more detailed instructions follow this : http://www.tprthai.net/bootmgr.htm

http://www.supergrubdisk.org/ provides a specialized rescue disk to restore Windows/Linux. I haven’t used it anytime though.

Developing software using virtualization – VirtualBox

Virtual Machines have made possible development strategies which didnt exist so far.Using my Windows laptop, I can install Linux/Solaris/Or some other version of Windows to develop applications on that platform.This also has additional benefit that in case something goes wrong with the target platform, all you need to do is just copy the back up of VM or revert to a known snapshot. Simple! No formatting/re installation cycles:) A couple of weeks ago, I switched  back to Windows (from Ubuntu). But I find Linux so fast and friendly that I still tend to do my coding under Ubuntu. For this I considered VMWare and VirtualBox.I have used VMWare in the past, it is very good and has many advanced features but it’s a resource hog. I would prefer to keep my CPU and disk activity as low as possible, so I set out to try VirtualBox (which now is a Sun company btw). VirtualBox takes a lot less disk space than VMWare, it can use existing VMWare images and provides almost equivalent functionality. It has decent audio, networking and USB support. Shared folders are useful feature too. However I couldn’t setup networking on my guest OS (Ubuntu 8.04).

I run Windows XP and Ubuntu as guest OS under my Windows XP laptop and performance has been decent. At times disk activity drags my system, but on the whole my 1GB RAM, 5400 rpm HDD and Intel Core Duo processor seem to handle the load gracefully. GNOME development kit, Solaris are now available as VMWare appliances, which can be downloaded and used very easily.