Sunday, November 28, 2010

Frozen Linux and Secure Files System Recovery with Magic Keys

Hi Friends,

Magic system recovery keys are combination of key hits that we can perform and kernel responds on priority. Before using magic keys we need to enable CONFIG_MAGIC_SYSRQ, by default sysreq compiled file (/proc/sys/kernel/sysrq) contains 1 that enables every possible sysreq.
 To customize this file we can use command :

echo "integer" >/proc/sys/kernel/sysrq 
 
integer 0 disable sysreq
integer 1 enables all functions of sysreq
Using:
echo command > /proc/sysrq-trigger 
 
command:
b : immediate reboot without unmunting.
c : perform system crash by null pointer de-referencing.
d : shows all locks that are held.
Rebooting your system due to freeze state (hanged state) may 
temper your file system.We can use magic key controls to handle
the situation that was initially used for kernel debugging.
Securely Restarting Hanged System:
Hit ALT+PrintScreen 
 
While holding the above keys press following given below 
keys one after other (press and hold for 3-4 seconds)
 
For Reboot: 
R S E I U B 
For Shut Down:
R S E I U O
 
What it does? : 
1. It takes control of keyboard back from X
2. Sends SIGTERM to all processes, allowing then to terminate racefully.
3. SIGKILL to force all processes terminate immediately.
4. Flushes data to disk.
5. Remounts or Unmounts all file systems.
 
For more details please refer:
http://en.wikipedia.org/wiki/Magic_SysRq_key  
 






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