headerphoto

Thu, 18 Sep 2008

Canon Rocks!!!

I found this amazing video on YouTube

This video shows Jeong-Hyun Lim who calls himself FunTwo performing Pachelbel's Canon. He calls his version "Canon Rock" - Simply amazing both in adaptation and performance.

 

Posted At: 21:43 | Posted In: /Miscallaneous | permanent link to this entry

Mon, 11 Aug 2008

Script to kill processes older than x days

On a linux farm sometimes there would be a need to kill processes that have been running for extended periods of time and notify the users before doing it. I had such a requirement and had to scour the internet for a lot of long hours to find a proper script to get this job done but couldn't find one. This script was written with ideas various sources and has been tested in an RHEL environment.

#!/bin/bash

# This is a script to identify user processes that have been running

# longer than a pre set number of days.

 

# **** BEGIN CONFIGURABLE PARAMETERS ****

# WARNING!! The following values should NOT be NULL.

# The script will not work with NULL values.

# Path to the logfile

LOG=/var/log/prockill

# List of groups to which users belong to

# The format should be 'group1| group2| group3| group4'

GROUP='everyone| utmp| 2000'

# Set the maximum age of a process before it is killed or email notification is sent

# If you want to notify users after 5 days and kill processes after 8 days then

# AGEKILL='1-| 2-| 3-| 4-| 5-| 6-| 7-| 8-'

# AGEMAIL='1-| 2-| 3-| 4-| 5-'

# AGE=3

AGEKILL='1-| 2-| 3-| 4-| 5-| 6-| 7-| 8-| 9-| 10-| 11-| 12-| 13-| 14-| 15-| 16-| 17-| 18-| 19-| 20-| 21-| 22-| 23-| 24-'

AGEEMAIL='1-| 2-| 3-| 4-| 5-| 6-| 7-| 8-| 9-| 10-| 11-| 12-| 13-| 14-| 15-| 16-| 17-| 18-| 19-| 20-'

AGE=3

# Email Address to send notifications to

MAIL=sheen@marfic.com

# Exceptions: processes that you dont want to kill

EXCP='ldap'

# **** END CONFIGURABLE PARAMETERS ****

 

# **** USER NOTIFICATION & PROCESS KILL ****

# Check if users have been notified

if [ -f /tmp/prockill.notified ]

then

# **** PROCESS KILL ****

if [ "`find /tmp/prockill.notified -mtime +$AGE`" != "" ] # Checking if the file was created x days ago

then # If file was created x days ago, its been x days since the users were notified.

# Demarc start of log

echo "**** Start List Processes Killed on `date` ****" >> $LOG

# Logging list of processes that match our conditions

ps -A -o user,pid,etime,group,args | egrep "$GROUP" | egrep -v "$EXCP" | grep "-" | egrep -v "$AGEKILL" >> $LOG

# Demarc start of log

echo "**** End List Processes Killed on `date` ****" >> $LOG

# Issuing SIGTERM to give processes a chance to exit gracefully

kill -15 `ps -A -o user,pid,etime,group,args | egrep "$GROUP" | egrep -v "$EXCP" | grep "-" | egrep -v "$AGEKILL" | cut -c10-15` > /dev/null

# Wait for 30 seconds to allow processes to terminate

echo "Waiting for processess to cleanly exit..."

sleep 30s

# Issuing SIGKILL to force all misbehaving processes to die.

kill -9 `ps -A -o user,pid,etime,group,args | egrep "$GROUP" | egrep -v "$EXCP" | grep "-" | egrep -v "$AGEKILL" | cut -c10-15` > /dev/null

rm -rf /tmp/prockill.notified # Clear the notified flag

exit 1

fi

else

# **** USER NOTIFICATION ****

# Get list of users and number of processes owned by them.

ps -A -o user,pid,etime,group | egrep "$GROUP" | egrep -v "$EXCP" | grep "-" | egrep -v "$AGEEMAIL" | cut -d' ' -f1 | uniq -c >> /tmp/prockill.eml

# Send email only if the filesize is greater than 0

if [ -s /tmp/prockill.eml ]

then

# Log notification.

echo "**** Start List Notified Processes on `date` ****" >> $LOG

echo "The following users have the indicated number of proceses that will be killed in 24 hours:"

cat /tmp/prockill.eml >> $LOG

echo "**** End List Notified Processes on `date` ****" >> $LOG

# Email Process list

mail -s "$HOSTNAME - Old Process Report" $MAIL < /tmp/prockill.eml

rm -rf /tmp/prockill.eml

touch /tmp/prockill.notified # Set notified flag

exit 1

else

# Log notification

echo "**** Start List Notified Processes on `date` ****" >> $LOG

echo "No old processes to kill!" >> $LOG

echo "**** End List Notified Processes on `date` ****" >> $LOG

exit 1

fi

fi

 



Posted At: 23:22 | Posted In: /Linux/Scripting | permanent link to this entry

Thu, 07 Aug 2008

One Bag Only

I had to do a lot of travelling in the recent past and one thing I realized that I absolutely despised was travelling heavy.

Learning how to to pack light isn't easy... I came across this website "http://www.onebag.com/" recently that gives you loads of tips and suggestions on how to travel light.

So if you are planning to go some place and hate travelling heavy, this website is for you.



Posted At: 00:21 | Posted In: /Miscallaneous | permanent link to this entry

Using APC PowerChute with VMWare ESX

In case of a power shutdown, we need to gracefully shutdown all virtual machines.
This is possible with an APC UPS that has a Network Management Card.

The process to do this is:
SSH to the vmware ESX server.
Execute the following commands to open up the required ports:

esxcfg-firewall -o 80,tcp,out,"APC PowerChute Port 80"
esxcfg-firewall -o 3052,tcp,out,"APC PowerChute Port 3052"
esxcfg-firewall -o 3052,tcp,in,"APC PowerChute Port 3052"
esxcfg-firewall -o 3052,udp,out,"APC PowerChute Port 3052"
esxcfg-firewall -o 3052,udp,in,"APC PowerChute Port 3052"
Then install the APC Network Shutdown Software
rpm -ihv pcns-2.2.1-100.i386.rpm

Then configure the software
/usr/local/bin/PowerChute/PCNSConfig.sh
Type 3 and press enter
Type in the IP address of the Management Card and press enter
Port 80
Enter the Username, Password and Authentication Phrase
Repeat for the second management card
Answer No to registering another management card
Answer Yes to starting the service

Now you can configure the event actions etc by pointing your web browser to http://servername:3052/

Other commands
/etc/rc.d/init.d/PowerChute stop
/etc/rc.d/init.d/PowerChute start
To uninstall, type rpm -e pcns

Please Note:
Once logged on to the web interface, click the ComputerName link
Specify the Configure Shutdown settings
UNTICK Turn off the UPS after the shutdown finishes.
Click Apply

This step is EXTREMELY important, otherwise once this server has shutdown it will power off the UPS regardless of other servers connected to the UPS.


Posted At: 00:21 | Posted In: /VMWare | permanent link to this entry

Wed, 16 Apr 2008

Viva Open Source
I'm proud to say that this blog entry was entirely made possible by open source. I am composing this blog using an open source HTML editor (nvu) on an open source operating system (ubuntu), hosted on an open source server (gentoo) running an open source blog server (blosxom). (If you are using a free linux OS, then we've completed the circle).
I wouldn't however be the first to boo at Microsoft (the veritable IBM of the '80s - depicted so by this legendary apple ad directed by Ridley Scott). Microsoft has in many ways paved the way for open source.
The open source revolution is what it is today because computers are no longer giant machines sitting in some research center. Computers today are nice looking boxes sitting under your desk, small heat generating machines sitting on your lap, tiny little devices that you depend on to keep you in touch, in short computers are here there and every where. The companies that made this possible are IBM, Microsoft and Apple. IBM for creating the PC, Apple for making the PC actually a personal computer and Microsoft for making the Operating System very user friendly and breaking the jinx that the PC was more important that the OS. The key change that these three companies made was to make the PC so popular that today no one can live without it or some variation of it.
"Open source is a development method for software that harnesses the power of distributed peer review and transparency of process. The promise of open source is better quality, higher reliability, more flexibility, lower cost, and an end to predatory vendor lock-in." is how the OSI would define Open Source.
What does this mean to the end user? Simply put, it reverses what we know today about popular software. Open Source software is mostly free for anyone who wants to use it and it empowers you to go do what you want to do without worrying too much about burning a hole in your pocket.

What does this mean to the enterprise? It means that spending on IT goes down by a huge margin.
Why isnt Open Source taking on the world then? Lack of knowledge of open source among end users is what I think is the single biggest reason why people arent looking at Open Source software as a workable alternative. Fear of the unknown and resistance to change come in close second.
How can this be overcome? The answer is obvious. There has to be a leap of faith - faith that reassures you to take a peek into the wonders of the Open Source revolution.
How can you do this? Its easy. A good starting point would be ubuntu's flavor of linux (its my personal favorite) as it really tries to make things easy for the end user and my word! do they read what the end user needs. Mark Shuttleworth (founder of Thawte and the second space tourist) who heads canonical is now commited to ubuntu's development and the ubuntu promise it to be forever free.
Go out and take that plunge - it will be the start of a great journey!


Posted At: 17:20 | Posted In: /Tech | permanent link to this entry