You are currently browsing the daily archive for February 24th, 2009.

This started as a notepad file on my desktop wherein I put anything that helped in my daily office work.

  • vi editor is by default not unicode i.e. it supports utf-8 and not utf-16. So if you have a file containing a unicode character (a 2 byte character) so when you open this file using vi, you will be seeing two funny looking characters instead of what you expected. The solution is to use vim, which is an enhanced version of  vi.
  • The following would round off a decimal number. This would always consider the last digit. So the algo involves calculating the decimal part of a number and then rounding off the number accordingly (Assuming that input contains the number to be rounded off):                                                   temp = inuput;
    while(temp / 10 > 1)
    ++i
    totalLen = input.ToString().length();
    decPartlen = totalLen – i – 1;
    float tenMult = pow(10, decPartLen);
    double result = ((int) ((tenMult * input) + 0.5)) / tenMult;OR

    temp = inuput;
    int len = (temp % 1).ToString().length() – 2;
    float tenMult = pow(10, len);
    double result = ((int) ((tenMult * input) + 0.5)) / tenMult;

  • If you by chance give an extra space at console and unix takes you to the next line e.g. HOME:>ls -l | egrep `^d’
    > t
    > quit
    > break
    > exit
    > :q
    > q
    >
    >
    >
    > end
    > exit
    > esc
    > fi
    > finish
    > end
    > break
    > exit
    > ^C
    you can come out of it  by pressing Ctrl + C. I’ve been stuck here a lot of time. And as you can see tried everything except the obvious at first.
  • UNIX does not have an option of listing only directories so you can try this: ‘ls -l | egrep `^d'' and for listing files use this ‘ls -l | egrep -v `^d'
  • Process Explorer is a wonderful nifty utility to check for what all dll’s have been loaded corresponding to your exe. This is freely available for download from Microsoft website. A similar utility on Linux is also available.  For KDE, KSysguard:
    http://docs.kde.org/development/en/kdebase/ksysguard/ and for GNOME there is an app called Gnome System Monitor:
    http://freshmeat.net/projects/gnome-system-monitor/. On Linux console you can use the ‘top’ or ‘ps’ command. Or you can also use htop, http://htop.sourceforge.net. Also try looking if ‘ldd’ solves your purpose.
  • To run a shell script from C++, you can use the following syntax: ‘long sysret = system(testscript.ksh);’. In most of the environments the return value zero would mean the system command executed successfully. Similarly if you want to run an exe or bat file from within a C++ code use CreateProcess command.
  • To output a parameter that has been passed to your script, to another file, use ‘echo $1 > $filename’. I was by mistake doing this instead ‘$1 > $filename’. $1 is essentially similar to giving the parameter $1 at the prompt. echo $1 would actually echo out the value and then that value can be redirected to your file.
  • If TaskManager has been disabled: http://windowsxp.mvps.org/Taskmanager_error.htm

find . -exec grep -l “string to find” {} \;
OR
find . -exec grep -H “string to find” {} \;
OR
grep -l “string to find” `find .`
OR
grep -H “string to find” `find .`

grep can search through your entire directory tree, scanning every file along the way:

grep -r “modules” .

You can also use grep to search for multiple words:

grep -r “text1\|text2\|text3″ .

In this example, grep will search only file names starting with “log”:
grep -lr “mod.*” ./log*

Search many files for a string. This example finds the string “thingy.” This is useful when I want to find, say, a CSS class name that has changed, and update it in all of my .js, .jsp and .jspf files:

find \( -name “*js” -o -name “*jsp” -o -name “*jspf” \) | xargs grep -niP ‘thingy’

To find for a particular filename use this command:

find . -name “filename” -print

To search for one or more strings in one or more files. E.g.

Search for the string ‘searchText' in all the files in current directory’ and print out each line that matches.

grep "searchText" *.*

Extended grep search all files for ’search” or ‘Text” case insensitive (-i) and if found display line number (-n) along with the line contents.

egrep -in "search|Text" *.*

Another way to search for a text in files with a particular extension:

find . -name “*.mk” | xargs grep “search.text”

AIX – OS
General stuff
http://www.scribd.com/doc/2309604/AIX-Disk-Tuning-Guidelines
1. Avoid disk I/O where possible. Turn off un-necessary logging.
2. Spread I/O over as many disks and adapters as economically feasible
3. Locate most active partitions at optimum spot on the disk – How?
4. Isolate most active partitions on their own disk
5. Randomize the sequencing of LV partitions across disks
6. Rule of thumb – There is a problem if
a. vmstat shows “wa” column averaging over 20-30% (wa = processor idle time due to disk / NFS I/O requests)
b. iostat shows %tm_act column averaging over 50-60% (tm_act = % of time the physical disk/tape was active. (bandwidth utilization for the drive) )
c. from iostat results: dividing Kbps by the tps gives the average disk transfer size(adts, not an official ETLA). This can be used to check if I/O is random ( adts 4K)
d. Formula to calculate Nbr of Disks for No Raid config – N = TPS / IOS (IOS=60 for random access and 1400 for serial access). For Raid see url..
Tools
nmon

DB2
General
Using BUFFPAGE parameter is a good thing. (See Details)
Tools
1. db2look – used to look at the schema. Can generate the DDL for selected objects.
db2look -d $DBLOC -i $DBUID -w $DBUID -t
-e > ddl_for_table.txt
db2look -d $DBLOC -i $DBUID -w $DBUID -e > ddl_for_schema.txt
2. db2 – This can launch an interactive shell or can be used to fire sqls directly or special commands. Depending on the node you are logged on some commands will not work
db2 “select * from item_master” > all_items.txt
db2 -x list applications (lists all the active connections, requires to be executed on the DB server)
db2 get snapshot for locks on (get current locks on the DB, DB Server only)
db2 get snapshot for all on (get all the snapshots, results can get huge!!, DB Server only)
db2 “alter table trans_invn alter column trans_invn_type_char drop expression”
db2 attach to user using (to change default node associated with a login into the DB Server)
3. db2advis – Tuning advisor (DB Server only). Makes recommendations for sql performance tuning. Note, this most likely _always_ recommends something. So we do need to cross check whether we need to do everything this tool advises. But it is a good starting point\
db2advis -d $DBLOC -i -t
4. db2exfmt – Formatter (DB Server only)5. db2expln – Explains plan.
db2expln -d $DBLOC -u $DBUID $DBPWD -o -f [-z delimiter -g Visual Graph]
http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/index.jsp?topic=/com.ibm.db2.luw.admin.cmd.doc/doc/r0005736.html

6. Catalog commands
a. Db2 catalog tcpip node remote server
b. Db2 catalog db as at node

Details
http://www-128.ibm.com/developerworks/db2/library/techarticle/anshum/0107anshum.html
Running stats on all the table and indexes
db2 -v connect to DB_NAME
db2 -v “select tbname, nleaf, nlevels, stats_time from sysibm.sysindexes”
db2 -v reorgchk update statistics on table all
db2 -v “select tbname, nleaf, nlevels, stats_time from sysibm.sysindexes order by stats_time”
db2 -v terminate

Running stats for one table
db2 -v runstats on table TAB_NAME and indexes all

Checking if stats have been run recently
db2 -v “select tbname, nleaf, nlevels, stats_time from sysibm.sysindexes”

Determine whether BUFFPAGE is being used
db2 -v connect to DB_NAME
db2 -v SELECT * from SYSCAT.BUFFERPOOLS
db2 -v connect reset
db2 -v terminate

Edit settings for BUFFPAGE
db2 -v connect to DB_NAME
db2 -v select * from syscat.bufferpools
db2 -v alter bufferpool IBMDEFAULTBP size -1
db2 -v connect reset
db2 -v update db cfg for dbname using BUFFPAGE bigger_value
db2 -v terminate

Verifying Buffer Pool is sufficient
db2 -v update monitor switches using bufferpool on
db2 -v get monitor switches db2 -v reset monitor all
– run your application –
db2 -v get snapshot for all databases > snap.out
db2 -v get snapshot for dbm >> snap.out
db2 -v get snapshot for all bufferpools >> snap.out
db2 -v reset monitor all db2 -v terminate

Buffer Hit Ratio (BHR) = (1 – ((buffer pool data physical reads + buffer pool index physical reads) / (buffer pool data logical reads + pool index logical reads) )) * 100%
Ideally BHR should be greater than 95%

LOGBUFSZ parameter….

db2 connect to user using

http://www.cse.yorku.ca/course_archive/2006-07/W/6421/db2notes/import.html