Monday, October 18, 2010

Shell Scripting and Infinite possibilties

To check a server is alive or not we simply ping that system, Similarly to check a process is alive or not (eg .running in infinite loop) we need some utilities. I hope this simple script might help you.

#!/bin/sh
# Written By: Pawan
# Last updated:YYYY-MM-DD

#set -x ### uncomment this line to enable debugging

## Script simply checks health of job running in infinite loop it might be your java, shell, python or any other job

jobs=( "abc.sh" "/home/user/cde.py" ) ## write your jobs those health is to be checked seperated by single space with absolute path or file name if same directory

## checking health of each job in loop

while [ "${jobs[${i}]}" != "" ]
do
loop_pid=`ps -ef | grep ${jobs[${i}]} | grep -v 'grep' | awk '{print $2}'`
then
echo "starting ${jobs[${i}]} if not running"
sh $job_path/${jobs[${i}]} &  ## "&" Will start your job in backend
else
echo "${jobs[${i}]} already running..."
fi
let i=i+1
done

Sunday, June 6, 2010

Python and peexpect module

Python peexpect module makes your automation process so simple and easy. There are some other modules like Paramiko but peexpect provides great flexibility for example suppose you wanted to remote login automatically without manual interference :


p1=pexpect.spawn('/usr/bin/ssh ' + ' -o HostKeyAlias=' + source_server_ip + ' ' + source_server_user + '@'+ source_server_ip )

now you can expect output returns as follows and handle those situation:

try:
        i=p1.expect(['password:',pexpect.TIMEOUT,pexpect.EOF,'continue connecting (yes/no)?','Host key verification failed.','Connection refused','Connection timed out'],timeout=120)

        if i==1:
                logging.error('Timeout')
                logging.debug(p1.before)
                sys.exit()
        if i==2:
                logging.error('Reached EOF')
                logging.debug(p1.before)
                sys.exit()
        if i==3:
                p1.sendline('yes')
                logging.info('RSA Key added')
                p1.expect('password:',timeout=MIN_TIMEOUT_TIME)              
               
        if i==4:
                logging.info('Host key Changed,calling  edit_known_hosts('+ip+')')
                edit_known_hosts(ip)
                logging.info(ip + " removed from known_hosts,calling Connect() again")
                Connect()        
               
        if i==5:
                logging.error('Connection refused by server')
                sys.exit()
        if i==6:
                logging.error('Connection timed out')
                sys.exit()

        logging.info('sending password:' + password)
        p1.sendline(password)              ## here you can specify password if everything went fine you are logged in to remote system.

    except Exception,e:
        print ('error:',str(e))



 you can explore more from Python Official documentation it was just a snapshot. Peexpect provides a simple and quite effective situation handling.

Note : peexpect module is not yet available for windows systems you can only use it in Linux flavors. 

Saturday, March 27, 2010

Indian Astrologer Live in US



M pandit: M pandit a live astrology service lets you speak to great Indian astrologers live from your place itself. M pandit telephonic astrology helps you find astrology related queries so easily from your mobile only. No prior appointment issue make a call and get connected to famous Indian astrologers.  


We all know planets are moving relative to each other, each particle on the earth is affected by the relative motion of planets. When our body is made of particles according to Einstein the great scientist then why not it will be affected .
In the olden days Indian Saints researched and developed the Astrology as a science that predicts several things in our life by calculating the relative positions of planets.




M pandit is bringing this olden Indian science in your reach, one call and you will be connected to Indian Astrologers live.


For more details Please visit:


M pandit 
you can also mail me on :


Pawan Singh

Tuesday, November 17, 2009

Fedora 12 Download

Most awaited Red Hat Fedora core 12 is now available for your personal computer. Fedora 12 has many new features like XZ compression rather than earlier gunzip. XZ compression scheme provide you with smaller packages and faster download feature.Apart from speedy update support, Fedora 12 has added features for blue tooth technology, virtualization, graphics and bug reporting.
Download Free :
http://fedoraproject.org/get-fedora

Thursday, November 12, 2009

Go System Programming Language

Google has changed the way of thinking about system programming. Google software engineers have finally made system programming in the palm of all men. Go programming language is open source that is robustly typed and garbage collected that also support concurrency programming. Implementation of Go programming language uses traditional compile/build model and faster than c, c++ code execution time. Pointers, structures, identifiers are included in a new and easy way in GO programming. Go has removed the limitation of C and C++ traditional system programming languages. For example:
package main

import "fmt"

func main() {
fmt.Printf("Hello, 世界\n")
}
There are same comment formats as in C and C++
//this is comment line
/* this is also same
As we used before in c , c++ */

For more details visit :
http://golang.org/

OR Watch This :
http://www.youtube.com/watch?v=wwoWei-GAPo