Monday, August 8, 2011

Basics of screen command in linux

Hi,
When you working on remote machine, you may come across with the situation, like, run a program or script for couple of hour or days. But when you logout of your local machine then your program automatically get killed because of loss of your session(Assigned shell gets terminated). So linux provides you to use "screen" command which allows you to make your program independent of shell. So even when you logout remotely even your program runs. Here the steps follows.
Log in to remote machine.
First check out "screen" is available in your remote machine.
If not present, use "apt-get install screen" cmd in ubuntu and install.
After successful installation.
Start ur program using below command.
#screen
Now ur program running in foreground only.
Now send detach signal by sending "Ctrl+a d" signal. Now your process will detached from your shell and running in background.
Now can logout from remote machine, process will run in remote machine without any effect.
Now after some time or even after some days, log in to remote machine and run "screen -ls". It will display all process running by using screen.
For attaching your process to shell run "screen -r ". Now your process will come foreground.
If multiple process are running using screens then "screen -r " below given example.
[root@local.host ~]#screen -ls
There are screens on:
29383.pts-7.localhost (Detached)
31899.pts-9.localhost (Detached)
2 Sockets in /var/run/screen/S-root.
These 29383, 31899 are pids of screens so
[root@local.host ~]# ps -ef |grep SCR
root 10787 15582 0 14:43 pts/9 00:00:00 grep SCR
root 29383 1 0 14:21 ? 00:00:00 SCREEN process1
root 31899 1 0 14:39 ? 00:00:00 SCREEN process2
To bring process to foreground
[root@local.host ~]#screen -r 29383
Now SCREEN process1 process comes to foreground.
So what are you looking for, give a try....

Wednesday, August 3, 2011

Enable core dump and debugging in linux

Run below two commands at shell or add to your bashrc files. this will enable the core dump.
ulimit -c unlimited
echo core.%e.%p.%s.%t > /proc/sys/kernel/core_pattern

Now start your execution. Say if any core dump generated then use below command


gdb coredumpFile

When you run this it will gdb displays where segfault occurred. Below copied few lines from gdb output.

Program terminated with signal 11, Segmentation fault.
#0 0x080483e3 in fun ()

Wednesday, July 20, 2011

Change order of packets in pcap file

Hi all, I have found new cap edit tool by which you can reorder the packets in pcap file. Not only ordering but also changing fields, fragmenting packets and adding vlan headers and so many other options. It has nice GUI will provide you user friendly experience.
Here is the GUI screen shot


Steps to install.
just check out the code from net
#svn co svn+http://code.google.com/p/packetsquare-capedit/source/browse/#svn/branches/0.0.1
#cd svn/branches/0.0.1/
#make
If you get any gtk+2 not installed issue then install gtk libs.
In ubuntu simply run below command
apt-get install libgtk2.0-dev
After successful installation, install capedit tool.
Once compiled you can run tool by simply typing below command.
./capedit
This tool is very usefull when your are working with protocol stacks...

Ok, just dig and explore more. Happy crafting packets :)

Friday, July 1, 2011

cmds grouping in expect script if we are expecting on same patron

Hi, below script is just to explain a data variable that can be used as list. So each value in the list are send to spawned program. This is helpful only if you are expecting on same string.
#!/usr/bin/expect -f


set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}


set timeout -1
set data "ls
date
ls -ltr
bla
bla
bla
exit"

#Spwan the new bash shell
spawn bash


match_max 100000

foreach line [split $data \n] {
expect "root@phaneedra:/home/phaneedra#"
send -- "$line\r"
sleep 1
}



Above foreach will split each line (each element) from data and copies to line variable. Now our script will look for "root@phaneedra:/home/phaneedra#" this and when ever it occurs send first and then next cmds.

This is just for example so it may not make much sense. But use full to test Cli interacting applications where expecting string patron not changed.