Friday, October 7, 2011

Tomcat: check if process is running

Put this in a cronjob and check every 5 min:


if [ `ps x | grep "java.*" | grep -v grep | grep -vi screen | wc -l` = "0" ]
cd /root/my_app
./start > /dev/null &

Wednesday, September 7, 2011

Run Linux in RAM

vmlinuz initrd=initrd.img ro quiet
root=CDLABEL=Fedora7-Live-i386 rootfstype=iso9660
liveimg live_ram

RAM <- /lib, /usr/lib (0.5G)
You can also make a folder in /usr called preload (or whatever) and mount that in RAM, link things back to /usr/lib and the symlinks that rely on (..) to point to /usr will still work. Lets you pick and choose whats loaded and could be automated with back script!

Saturday, July 23, 2011

Install VMware tools on Linux

  1. Install your Red Hat or CentOS virtual machine (VM) using whichever mechanism works best for your environment. I use a Preboot eXecution Environment, or PXE, bootserver for such things.
  2. Configure the Red Hat or CentOS VM using your standard procedures.

Then, perform the following additional configuration steps:

  1. rpm --import
  2. Use the following script to create a repository file useable by the yum command.

    Note that you need to substitute with 3.5u2, 3.5u3, or 3.5u4. You also need to substitute with either i686 or x86_64 depending on whether your VM is a 32-or 64-bit VM, respectively.

cat > > /etc/yum.repos.d/vmware-tools.repo < < EOF [vmware-tools]
name=VMware Tools for Red Hat Enterprise Linux $releasever - $basearch



For example, within a 32-bit VM where the ESX version is v3.5 U3 I used the following:

cat > > /etc/yum.repos.d/vmware-tools.repo < < EOF
name=VMware Tools for Red Hat Enterprise Linux $releasever - $basearch

To remove the tools, make the following commands:

  1. yum remove vmware-tools-* open-vm-tools-*
  2. yum -y install xorg-x11-drv-vmware xorg-x11-drv-vmmouse
  3. yum -y install vmware-tools open-vm-tools-xorg-drv-display open-vm-tools-xorg-drv-mouse

Attempting this method with RHEL 5 Update 3 versions of VMware Tools, however, will result in failure to install VMware Tools as the GPG key is handled incorrectly. The only solution is to disable GPG checking. To do so, change the line within /etc/yum.repos.d/vmware-tools.repo from


Once completed, you can safely update and install VMware Tools without GPG errors.

Upgrading VMware Tools
It's easy to upgrade VMware Tools when you update your Red Hat distribution by using the following command:

yum -y update

If, however, your kernel is too new, you can't update from the VMware Tools OS-specific package repository and will have to build drivers locally. To do so, execute the following commands. Of importance: will be 3.5u2, 3.5u3 or 3.5u4. Also, you'll most likely want to run these commands on a development machine, as you need to install compilers and other build tools. The result will be a redistributable VMware Tools kernel module image that you can install in other VMs.

  1. yum list < /tmp/t

  2. vname=`grep vmware-tools /tmp/t|awk '{print $2}'`
  3. version=`basename $vname .el`
  4. wget$version.src.rpm
  5. wget$version.src.rpm
  6. yum -y install yum-utils rpm-build

    You may need to double-check the version of kernel-devel that is installed by the next command so that it matches your running kernel. In some cases, it will not be the latest version of the kernel.

  7. yum-builddep -y open-vm-tools-kmod-$version.src.rpm vmware-tools-kmod-$version.src.rpm
  8. rpmbuild --rebuild open-vm-tools-kmod-$version.src.rpm
  9. rpmbuild --rebuild vmware-tools-kmod-$version.src.rpm
  10. rpm -ivh /usr/src/redhat/RPMS/i386/open-vm-tools-kmod -`uname -r`-$version.i386.rpm /usr/src/redhat/RPMS/i386/vmware-tools-kmod-`uname -r`-$version.i386.rpm

-Edward L. Haletky

Tuesday, June 21, 2011

sha2 encryption in ruby

require 'digest/sha2'; hash =; hash << "text to encrypt"; hash.to_s

<< basically adds the parameter to the object. 'f' << 'oo' # -> 'foo' and [1] << 2 # -> [1,2]

but it might be a left shift also ;) 2 << 3 # -> 16
it shifts the bit representation of a number. 0b001 << 1 # -> 0b010
with 0b001 == 1 and 0b010 == 2

Thursday, May 26, 2011

Web Developer Tools

General debugging tools:
Firebug -
Popular Firefox extension for web developers.
Web Developer - Another Firefox extension containing good set of tools.
JS Deminifier - Good for expending minified JS.
Firecookie - Cookie manager for Firebug.
JS beautifier -
Reformats JavaScript source code to make it more readable.
JS beautifier2 - Reformats JavaScript source code.

Web Application Testing Frameworks:
Watir - Ruby based framework for browser automation. examples
Webdriver - Browser automation framework.

Friday, May 6, 2011

Create Rails project with any version

gem list
rails (3.0.5,2.3.11)

rails -v
Rails 3.0.5

#Create a rails project with version 2.3.11
rails _2.3.11_ MyProject

Monday, February 7, 2011

MySql dump with Cronjob

0 0 * * 0 /usr/bin/mysqldump -uroot -p'PASS' DBName > /path/DB_backup/$(date +\%Y-\%m-\%d_\%Hh\%M).sql

example output file: