Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Tuesday, April 28, 2009

Useful wireshark startup options

Sometime when looking at TCP/IP traffic on multiple ports it's useful to start up several wireshark instances and have each capture traffic on distinct port, and give the window a specific title:


sudo wireshark -o "gui.window_title:Data Server on $SERVER_PORT -" -i lo -p -f "port $SERVER_PORT" -k &


-i lo
capture packets on local loopback interface

-p
don't go into promiscuous mode

-f "port $SERVER_PORT"
use the following filter (specific port)

-k
start capture immediately

Thursday, April 23, 2009

How to print process environment variables

Here is a script that prints process environment variables given process ID in Linux:


#!/bin/bash
if [ $# -ne 1 ] ; then
echo "Usage: `basename $0` process_id"
echo "Prints process environment variables"
exit 1
fi

sed 's/\o0/\n/g' /proc/$1/environ

Tuesday, January 06, 2009

Trapping errors in bash

Bash has functionality similar to exceptions in java.
If we want to handle any sort of error, we can add a handler function
and exit with an error code. This sure beats checking exit code
after every command.

function error {
echo Error
exit 1
}
trap error ERR

Monday, November 24, 2008

Script to reuse Eclipse project when switching code directory underneath

We're using subversion transactions here at Snaplogic: when working on a bug fix or new feature we create a branch off main tree, then after the change is complete we merge it into the main tree. Transaction management can be easily automated using shell scripts: tx-begin, tx-commit, etc.

However if you are using Eclipse there is a problem that each time you create a transaction you have to recreate your project. Even though you're working on the code, and have set up your project paths, and environment, and launch configurations, you have to recreate all that when you switch from one transaction to another, because each transaction resides in a different directory.

You want to have transactions in separate directories to be able to go back and forth between them, if you are working on several at a time, and for historical purposes. It may seem that you can overcome this limitation of Eclipse by using symlinks, and you can, to a degree, however Eclipse converts the symlink to the absolute file system path, and stores that in its project file.

So this is the missing piece of the puzzle of reusing the same Eclipse project when switching project directories underneath.

This python script will edit the .location file stored in the .metadata directory of Eclipse's resources plugin.

#!/usr/bin/python
# Pass destination path as the parameter
import sys

LOCATION = "/home/dmitri/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/code/.location"
PREFIX = "URI//file:"
replace_path = PREFIX + sys.argv[1]
file = open(LOCATION, "rb")
contents = file.read()
start = contents.index(PREFIX)
length = ord(contents[start-1:start])
sys.stdout.write(contents[0:start-2] + chr(0) + chr(len(replace_path)) + replace_path + contents[start + length:])


You run it as follows:

fix-eclipse /home/dmitri/workspace/all-code/dmitri_snaphome-2/snaplogic/python > /tmp/.location
cp /tmp/.location /home/dmitri/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/code/.location