9/26/08

truss

truss is a command to trace system calls and signals

SYNOPSIS
truss [-fcaeildDE] [- [tTvx] [!] syscall ,...]
[- [sS] [!] signal ,...] [- [mM] [!] fault ,...]
[- [rw] [!] fd ,...]
[- [uU] [!] lib ,... : [:] [!] func ,...]
[-o outfile] command | -p pid[/lwps]...

DESCRIPTION
The truss utility executes the specified command and produces a trace ofthe system calls it performs, the signals it receives, and the machine faults it incurs. Each line of the trace output reports either the fault or signal name or the system call name with its arguments and return value(s).
System call arguments are displayed symbolically when possible using defines from relevant system headers. For any path name pointer argument, the pointed-to string is displayed.
Error returns are reported using the error code names described in intro(3). If, in the case of an error, the kernel reports a missing privilege, a privilege name as described in privileges(5) is reported in square brackets ([
]) after the error code name.
Optionally (see the -u option), truss also produce an entry/exit trace of user-level function calls executed by the traced process, indented to indicate nesting.

Why to know about truss?

In the day today admin job, you may want to see what a process is doing? or you may want to check an installation process. Or ur installation process is failing, you want check whats going on. You use truss in such conditions.

Some examples:

truss -p pid
gives you that specific pids systemcalls
$ truss -p 883
/14: lwp_cond_wait(0x0193BFF8, 0x0193BFE0, 0xD287F710, 0) Err#62 ETIME
/14: lwp_cond_broadcast(0x016BA688) = 0
/14: lwp_cond_broadcast(0x01299A98) = 0
/205: lwp_cond_wait(0x016BA688, 0x016BA670, 0xD187F748, 0) = 0
/205: lwp_cond_broadcast(0x0193BFF8) = 0
/14: lwp_cond_wait(0x0193BFF8, 0x0193BFE0, 0x00000000, 0) = 0
/205: lwp_mutex_wakeup(0x0193BFE0) = 0
/14: lwp_mutex_timedlock(0x0193BFE0, 0x00000000) = 0
/205: lwp_mutex_wakeup(0x000F8AD8) = 0
/14: lwp_mutex_timedlock(0x000F8AD8, 0x00000000) = 0
/14: lwp_cond_broadcast(0x000D2E80) = 0
/205: stat64("/software/IBM/WebSphere/AppServer/profiles/AppSrv01/installedApps/hornblowerNode01Cell/FRPApp.ear/FRPApp-WebModule.war/WEB-INF/classes/us/ny/state/oag/model/OrganizationDetail.class", 0xD187F628) = 0

883 is a WebSphere pid.

$ truss -o example.out -p 883
truss traces pid 883 and outputs to example.out

$truss -o example.out install.sh
install.sh is an installer of a software. truss traces the installation process's system calls and outputs to example.out

9/18/08

find, grep

find:
NAME
find - find files
SYNOPSIS
/usr/bin/find [-H -L] path... expression
/usr/xpg4/bin/find [-H -L] path... expression
DESCRIPTION
The find utility recursively descends the directory hierar- chy for each path seeking files that match a Boolean expres- sion written in the primaries given below.
find is able to descend to arbitrary depths in a file hierarchy and does not fail due to path length limitations (unless a path operand specified by the application exceeds PATH_MAX requirements).

Examples :
find . -name "bla.log" -print
This command will search in the current directory and all sub directories for a file named bla.log.
Note: The -print option will print out the path of any file that is found with that name. In general -print wil print out the path of any file that meets the find criteria.

find /usr/src -not \( -name "*,v" -o -name ".*,v" \) '{}' \; -print
This command will search in the /usr/src directory and all sub directories. All files that are of the form '*,v' and '.*,v' are excluded. Important arguments to note are:
-not means the negation of the expression that follows
\( means the start of a complex expression.
\) means the end of a complex expression.
-o means a logical or of a complex expression. In this case the complex expression is all files like '*,v' or '.*,v'
find . -exec grep "size" '{}' \; -print
This command will search in the current directory and all sub directories. All files that contain the string will have their path printed to standard output.
grep:

NAME
grep - search a file for a pattern
SYNOPSIS
/usr/bin/grep [-bchilnsvw] limited-regular-expression [filename...]
/usr/xpg4/bin/grep [-E -F] [-c -l -q] [-bhinsvwx] -e pattern_list... [-f pattern_file]... [file...]
/usr/xpg4/bin/grep [-E -F] [-c -l -q] [-bhinsvwx] [-e pattern_list...] -f pattern_file... [file...]
/usr/xpg4/bin/grep [-E -F] [-c -l -q] [-bhinsvwx] pattern [file...]
DESCRIPTION
The grep utility searches text files for a pattern and prints all lines that contain that pattern. It uses a com- pact non-deterministic algorithm.
Be careful using the characters $, *, [, ^, , (, ), and \ in the pattern_list because they are also meaningful to the shell. It is safest to enclose the entire pattern_list in single quotes '...'.
If no files are specified, grep assumes standard input. Nor- mally, each line found is copied to standard output. The file name is printed before each line found if there is more than one input file.
/usr/bin/grep The /usr/bin/grep utility uses limited regular expressions like those described on the regexp(5) manual page to match the patterns.
/usr/xpg4/bin/grep The options -E and -F affect the way /usr/xpg4/bin/grep interprets pattern_list. If -E is specified, /usr/xpg4/bin/grep interprets pattern_list as a full regular expression (see -E for description). If -F is specified, grep interprets pattern_list as a fixed string. If neither are specified, grep interprets pattern_list as a basic regular expression as described on regex(5) manual page.

Example:
U want to find a string "size" in a folder and in its subfloders. This is the example
grep -i size `find . name *.* -print`

Grep can be used in so many ways and for so many reasons.
If I want to check the java processes
ps -ef grep java
If I want to check java processes owned by a particular user
ps -ef grep java grep websphe

If I want to check network statistics and specifically for a specific host
netstat -a grep hostname
..
netstat -a grep 8080

and so on.

9/9/08

cp

U might know this
But, just FYI

If you want to copy a file in UNIX, cp is the command
man cp gives the following info.
cp - copy files

SYNOPSIS /usr/bin/cp [-fip@] source_file target_file
/usr/bin/cp [-fip@] source_file... target
/usr/bin/cp -r -R [-H -L -P] [-fip@] source_dir... target
/usr/xpg4/bin/cp [-fip@] source_file target_file
/usr/xpg4/bin/cp [-fip@] source_file... target
/usr/xpg4/bin/cp -r -R [-H -L -P] [-fip@] source_dir... target


Usage Example:

$ mkdir testcp
$ mkdir testcpdest
$ cd testcp
$ touch x1.txt
$ cd ..
$ cp -r testcp testcpdest

I made a dir called testcp (which is the source dir)
I made another dir called testcpdest (destination dir)
I have touched a file x1.txt in testcp
I have copied testcp to testcpdest with files using cp -r meaning copy recursively.

Another ex.,
I have a file like this
-rw-r--r-- 1 websphe websphe 13593 Mar 18 11:53 n1.log
I want to cp it to n2.log with the same time stamp and same uid,gid permissions. This is the way
cp -p n1.log n2.log
n2.log will have same time stamp and other info as n1.log
-rw-r--r-- 1 websphe websphe 13593 Mar 18 11:53 n2.log
-rw-r--r-- 1 websphe websphe 13593 Mar 18 11:53 n1.log