About Me

My photo
Working as Technical Lead in CollabNET software private limited.

Tuesday 31 March, 2009

Find and Grep

The find and grep are very usefull commands for development.

When you want to grep a content for the matching files, below commands will help you out.


In linux:
find /tmp -name 'page.xml' -print0 | xargs -0 grep "view_link=\"ReportView" | awk '{print $1}' | wc -l

In solaris:
find /tmp -name 'page.xml' -exec grep "view_link=\"ReportView" {} \; | wc -l

In the above command I'm trying to find page.xml inside /tmp dir and then search content "view_link=\"ReportView" from the find output.

Monday 30 March, 2009

STOP and START a running process.

Send signals to the running process.

# sending STOP signal to the process will halt the process in it's current state.
sudo kill -STOP $pid.

# To confirm the process is stopped for a moment
sudo strace -p $pid. #this will leave traces of "STOPPED".

# send CONT signal to resume the process to start it's work
sudo kill -CONT $pid.


Inorder to make the process idle (to simulate deadlock situation) I've used the above technique to stop the process and test the status of the process.

Monday 23 March, 2009

To print shared library dependencies

To know what are the libraries used by any program.

>>ldd /usr/bin/svn | grep db
>>libdb-4.7.so => /lib/libdb-4.7.so (0x00154000)
>>libdb-4.3.so => /lib/libdb-4.3.so (0x00cb0000)

Friday 20 March, 2009

Enable pgsql logging

Some days back I came to situation to find when the table rows are inserted and deleted by an unknown thread!.

Got an idea from one of my colleague and enabled the pgsql logging. It worked great :)

To enable logging

# Edit the pgsql configuration file
/var/lib/pgsql/data/postgresql.conf

# Under section # ERROR REPORTING AND LOGGING
# Edit the logging options and set your preferrence!.


...
log_directory = 'pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_line_prefix = '%u %h %t'
log_statement = 'all'
log_hostname = on
...


# Go to pgsql logging dir and tail for the logfile.
cd /var/lib/pgsql/data/pg_log/