Tuesday, December 14, 2010

Learning UNIX - IV

________________________________________

Advance Unix Management
________________________________________

xyx:/>compress
-command compresses a file and returns the original file with .z extension, to uncompress this filename’s file use uncompress filename command.

Available Options
-bn limit the number of bits in coding to n
-c write to standard output
-f compress conditionally, do not prompt before overwriting files
-v Print the resulting percentage of reduction for files
________________________________________

xyx:/>uncompress
- command file uncompresses a file and return it to its original form.
uncompress filename.Z this uncompressed the compressed file to its original name.
-c write to standard output without changing files
________________________________________

xyx:/>cpio
- command is useful to backup the file systems. It copy file archives in from or out to tape or disk, or to another location on the local machine.

cpio flags [options]
It has three flags, -i, -o, -p
cpio -i [options] [patterns]
-> cpio -i copy in files who names match selected patterns
-> If no pattern is used all files are copied in
-> It is used to write to a tape
cpio -o
-> Copy out a list of files whose name are given on standard output
cpio -p
-> Copy files to another directory on the same system.
Options
-a reset access times of input files
-A append files to an archive (must use with -o)
-b swap bytes and half-words. Words are 4 bytes
-B block input or output using 5120 bytes per record
-c Read or write header information as Ascii character
-d create directories as needed
-l link files instead of copying
-o file direct output to a file
-r rename files interactively
-R ID reassign file ownership and group information to the user's login ID
-V print a dot for each file read or written
-s swap bytes
-S swap half bytes
-v print a list of filenames

Imp Examples
-> find . -name "*.old" -print | cpio -ocvB > /dev/rst8 will backup all *.old files to a tape in /dev/rst8
-> cpio -icdv "save"" < /dev/rst8 will restore all files whose name contain "save" -> find . -depth -print | cpio -padm /mydir will move a directory tree.
________________________________________

xyx:/>dump
- command is useful to backup the file systems, copies all the files in file system that have been changed after a certain date. This command is good for incremental backups on HP Unix
date is derived from /var/adm/dump dates and /etc/fstab.

/usr/sbin/dump [option [argument ...] file system]
Options where
where 0-9 dump level. 0 option causes entire file system to be dumped or copied
b blocking factor taken into argument
d density of tape, default value is 1600
f place the dump on next argument file instead of tape
________________________________________

xyx:/>pack
- command compacts each file and combine them together into a filename.z file. The original file is replaced. pcat and unpack will restore packed files to their original form.

Available Options
-p Print number of times each byte is used
-f Force the pack even when disk space isn't saved
To display Packed files in a file use pcat command
-> pcat filename.z
To unpack a packed file use unpack command as unpack filename.z
________________________________________

xyx:/>tar
- command creates an archive of files into a single file. tar copies and restore files to a tape or any storage media.

Examples:
xyx:/>tar cvf /dev/rmt/0 /bin /usr/bin creates an archive of /bin and /usr/bin, and store on the tape in /dev/rmt0.
xyx:/>tar tvf /dev/rmt0 will list the tape's content in a /dev/rmt0 drive.
xyx:/>tar cvf - 'find . -print' > backup.tar will creates an archive of current directory and store it in file backup.tar.

Functions and options:
c creates a new tape
r append files to a tape
t print the names of files if they are stored on the tape
x extract files from tap
b n use blocking factor of n
l print error messages about links not found
L is symbolic links
v print function letter (x for extraction or a for archive) and name of files.
________________________________________


xyx:/>mt
- command is used for tape and other device functions like rewinding, ejecting, etc. It give commands to tape device rather than tape itself. mt command is BSD command and is seldom found in system V unix versions.
syntax is
mt [-t tapename] command [count]
mt for HP-UX accept following commands.

Important Examples to use
mt -t /dev/rmt/0mnb rew will rewind the tape in this device
mt -t /dev/rmt/0mnb offl will eject the tape in this device

________________________________________

xyx:/>calendar
- command reads your calendar file and displays only lines with current day.

Examples:-
12/20 Test new software.
1/15 Test newly developed 3270 product.
1/20 Install memory on HP 9000 machine.
On dec 20th the first line will be displayed. you can use this command with your crontab file or in your login files.
________________________________________

xyx:/>nohup
- command, is used with prefix of any command, which continue running the command even if you shut down your terminal or close your login session.

xyz:/>nohup top
________________________________________

xyx:/>tty
- command is used to display terminal information.
-l will print the synchronous line number
-s will return only the codes: 0 (a terminal), 1 (not a terminal), 2 (invalid options) (good for scripts)
________________________________________

Handy for Unix Shell Programming
________________________________________

Shell programming concepts and commands:
Shell programming is an integral part of Unix operating system. It is command line user interface to Unix system, User have an option of picking an interface on Unix such as ksh, csh, or default sh, these are called shells. Shell programming is used to automate many tasks. ________________________________________

Bourne Shell (sh shell):-
sh or Bourne shell is default shell of Unix operating systems and is the simplest shell in Unix systems.

Ksh shell (Korn):-
Ksh or Korn shell is widely used shell.

csh or c shell:-
csh is second most used shell.

echo command
The echo utility writes its arguments, separated by BLANKs and terminated by a NEWLINE, to the standard output. If there are no arguments, only the NEWLINE character will be written.
echo is useful for producing diagnostics in command files, for sending known data into a pipe, and for displaying the contents of environment variables.

line command
The line utility copies one line (up to and including a new-line) from the standard input and writes it on the standard output. It returns an exit status of 1 on EOF and always prints at least a new-line. It is often used wwithin shell files to read from the user's terminal.

sleep command
The sleep utility will suspend execution for at least the integral number of seconds specified by the time operand.
Example 1: Suspending command execution for a time
To execute a command after a certain amount of time:
example% (sleep 105; command)&
Example 2: Executing a command every so often
example% while true
do
command
sleep 37
done

test command
The test utility evaluates the condition and indicates the result of the evaluation by its exit status. An exit status of zero indicates that the condition evaluated as true and an exit status of 1 indicates that the condition evaluated as false.

cc compiler (c programming language compiler).
Since Unix is itself is written in C programming language, most Unix operating systems come with c compiler called cc.

Tuesday, December 7, 2010

Learning UNIX - III

File Transfer and Communication Management

________________________________________

xyx:/>cu command, is used for communications over a modem or direct line with another Unix system.
________________________________________

xyx:/>ftp command is used to execute for files transfer over two systems.

-d enable debugging.
-g disable filename globing.
-i turn off interactive prompts.
-v verbose on. Show all responses from remote server.
________________________________________

xyx:/>login
command invokes a login session to a Unix box, System prompts you to enter userid and password.

xyx:/>rlogin command is used to log on to remote Unix systems, user must have permissions on both systems as well as same user id, or an id defined in .rhosts file.
xyx:/>rlogin host
________________________________________

xyx:/>talk
command used to invoke talk program available on all unix system which lets two users exchange information back and forth in real time.

xyx:/>talk userid@hostname
________________________________________

xyx:/>telnet - command invokes a telnet protocol which lets you log on to different unix, vms or any machine connected over TCP/IP protocol, IPx protocol or otherwise.

xyx:/>telnet host1
xyx:/> telnet
telnet>
________________________________________

xyx:/>vacation
command is used for out of office message to be send. It returns a mail message to sender announcing that you are on vacation.
/export/home/crk> vacation
This program can be used to answer your mail automatically
when you go away on vacation.
You need to create a message file in /export/home/crk/.vacation.msg first.
Please use your editor (vi) to edit this file.
"/export/home/crk/.vacation.msg" 4 lines, 130 characters
Subject: away from my mail
I will not be reading my mail for a while.
Your mail regarding "$SUBJECT" is read when I return.
N.B:- To disable this feature, use mail -F " "
-d will append the date to the log file.
-F user will forward mail to user when unable to send mail to mail file.
-l log file will record in the log file the names of senders who received automatic reply.
-m mail file will save received messages in mail file.
________________________________________

xyx:/>write
command initiate an interactive conversation with user.

xyx:/>write user1 tty
________________________________________
System reporting and Status Management
________________________________________

xyx:/>at command.
at command is also used like crontab command, to schedule jobs.

-f file execute commands in a file.
-m sends mail to user after job is completed.
-l list all jobs that are scheduled and their jobnumbers.
-r job number will remove specified jobs that were previously scheduled.
________________________________________

xyx:/>chmod Command is used to change permissions on a file.
xyx:/>ls -la test.txt
-rw-rw-rw- 1 qtr pmpcr 135 OCT 20 16:14 test.txt
-rw-rw-rw- meaning that owner can read and write file, member of the owner's group can read and write this file and anyone else connected to this system can read and write this file., next qtr is owner of this file pmpcr is the group of this file, there are 135 bytes in this file, this file was created on Oct 20 at time16:14 and at the end there is name of this file.
xyx:/>chmod 600 file1
________________________________________

xyx:/>chgrp command is used to change the group of a file or directory.
xyx:/>chgrp [options] newgroup files
Newgroup is either a group Id or a group name located in /etc/group .
Available Options:
-h will change the group on symbolic links.
-R recursively descend through directory changing group of all files and subdirectories.
________________________________________

xyx:/>chown command.
chown command to change ownership of a file or directory to one or more users.

xyx:/>chown options new owner files
Available important Options
-h will change the owner on symbolic links.
-R will recursively descend through the directory, including subdirectories and symbolic links.
________________________________________

xyx:/>crontab is used to schedule jobs. Permission to run this command should have been granted.
Normally Jobs are scheduled in five numbers, as follows.
Minutes 0-59
Hour 0-23
Day of month 1-31
month 1-12
Day of week 0-6 (0 is sunday)
Example
To schedule a job which runs from script named backup_jobs in /usr/local/bin directory on sunday (day 0) at 11.25 (22:25) on 15th of month.

* represents all values.
25 22 15 * 0 /usr/local/bin/backup_ xyx:/>jobs
The * here tells system to run this each month.
Syntax is
xyx:/>crontab file ## To create a file with the scheduled jobs like above
xyx:/>crontab file1 # to schedule job
________________________________________

xyx:/>date - command displays to days date, to use it type date at command prompt
xyx:/>date
Fri Oct 20 16:10:58 EDT 2010

________________________________________

xyx:/>df
df command displays information about mounted filesystems.
xyx:/>df
/ (/dev/md/dsk/d0 ): 3838540 blocks 431434 files
/proc (/proc ): 0 blocks 29848 files
/etc/mnttab (mnttab ): 0 blocks 0 files
/dev/fd (fd ): 0 blocks 0 files
/var (/dev/md/dsk/d20 ): 2559692 blocks 587286 files
/var/run (swap ):31292080 blocks 789270 files
/dev/vx/dmp (dmpfs ):31292080 blocks 789270 files
/dev/vx/rdmp (dmpfs ):31292080 blocks 789270 files
/tmp (swap ):31292080 blocks 789270 files
/opt (/dev/md/dsk/d30 ): 2509926 blocks 609248 files
/opt/crk (/dev/md/dsk/d40 ):32416940 blocks 2240301 files

Available Options
-b show only the number of free blocks.
-e show only the number of free files.
-k list allocation in kilobytes.
-l show only on local file systems.
-n list only the file system name type
________________________________________

xyx:/>du
du command displays disk usage.
________________________________________

xyx:/>env
env command displays all the variables set in your profile
________________________________________

xyx:/>finger - command used to display information about local and remote users.
xyx:/>finger user1@abc
________________________________________

xyx:/>ps
ps command is the most useful command for systems administrators. It reports information on active processes.
Available options.
-a Lists all processes in system except processes not attached to terminals.
-e Lists all processes in system.
-f Lists a full listing.
-j print process group ID and session ID.
xyx:/>ps -eafj |more
UID PID PPID PGID SID C STIME TTY TIME CMD
root 0 0 0 0 0 Sep 08 ? 0:19 sched
root 1 0 0 0 0 Sep 08 ? 2:51 /etc/init -r
root 2 0 0 0 0 Sep 08 ? 0:00 pageout
root 3 0 0 0 1 Sep 08 ? 634:05 fsflush
root 6817 1 6817 6817 0 Sep 08 ? 0:00 /usr/lib/saf/sac -t 3
00
root 590 1 590 590 0 Sep 08 ? 0:06 /usr/lib/inet/xntpd
root 689 1 0 0 0 Sep 08 ? 0:00 /sbin/sh - /usr/lib/v
xvm/bin/vxconfigbackupd
root 20 1 20 20 0 Sep 08 ? 3:48 vxconfigd -x syslog -
m boot
________________________________________

xyx:/>ruptime - command tells the status of local networked machines.

Available options.
-a include user even if they've been idle for more than one hour
-l sort by load average
-r reverse the sort order
-t sort by uptime
-i sort by number of users
________________________________________

xyx:/>shutdown command executed by root. To gracefully bring down a system, shutdown command is used.
-gn use a grace-period of n seconds (default is 60).
-ik tell the init command to place system in a state k.
s single-user state (default)
shutdown for power-off
1 like s, but mount multi-user file systems
5 stop system, go to firmware mode
6 stop system then reboot
-y suppress the default prompt for confirmation.
________________________________________

xyx:/>stty - command sets terminal input output options for the current terminal.
Without options stty reports terminal settings.

-a report all options.
-g report current settings.
Available Modes
0 hang up phone.
n set terminal baud.
erase keyname, will change your keyname to be backspace key.
________________________________________

xyx:/>who - command displays information about the current status of system.
who options file
Who as default prints login names of users currently logged in.
Available Options
-a use all options.
-b Report information about last reboot.
-d report expired processes.
-H print headings.
-p report previously spawned processes.
-u report terminal usage.
________________________________________
File Redirection Management
________________________________________
xyx:/>cal > cal.txt , create a new file called cal.txt that has calendar for current month.
> sign redirects output from stdout (screen) to a file. If file already exists, it will over right the content with latest information being redirected
>> will append the file if it is already existing

Monday, December 6, 2010

Learning UNIX - II

Comparison and Search Management
________________________________________

xyx:/>diff command. Compares the two files and print out the differences between them

Let two ascii text files file1 and file2
Contents of file1:
This is a test file to compare the file contents
This is a test file to compare the file contents
This is a test file to compare the file contents
This is a test file to compare the file contents

Contents of file2 contains
This is a second test file to compare the file contents
This is a test file to compare the file contents
This is a test file to compare the file contents
This is a test file to compare the file contents
xyx:/>diff file1 file2
0a1
> This is a second test file to compare the file contents
3d3
This is a test file to compare the file contents
________________________________________

xyx:/>cmp command. Compares the two files, similarly as diff.
xyx:/>cmp file1 file2
file1 file2 differ: char 12, line 1
________________________________________

xyx:/>dircmp Command compares two directories. Let us say dir1 and dir2 and each has 5-10 files in it. Then
xyx:/> dircmp dir1 dir2
Nov 20 14:14 2010 dir1 only and dir2 only Page 1
./userfile/duplicate_Tue.lo ./add_test_profiles.sh
./ userfile/duplicate2 _Tue_09 ./afiedt.buf
./ userfile/duplicate3 _Fri.log ./alter_user_profiles.sh
./ userfile/duplicate4 _Fri_113 ./kb.sh

________________________________________

xyx:/>grep Command is the most useful search command. Mostly used with combination with other commands like PS command, to find processes running on system, a pattern in a file, search one or more files to match an expression etc.

xyx:/> ps -ef | grep sleep will display all the sleep processes running in the system as follows.
root 15258 4190 0 14:21:25 ? 0:00 sleep 300
root 15890 15879 0 14:24:59 ? 0:00 sleep 360
_______________________________________

xyx:/>find command very useful for search of any file anywhere , provided that file and directory you are searching has read write permission set to you ,your group or all.
Some common Examples:

xyx:/>find $crk -print will lists all files in crk home directory.
xyx:/>find /crkdir -name client1 -print will list all files named client1 in /crkDir directory.
xyx:/>find / -type d -name 'man*' -print will list all manpage directories.
xyx:/>find / -size 0 -ok rm {} \; will remove all empty files on system.

_______________________________________

Text processing tools
________________________________________

xyx:/>cut command selects a list of columns or fields from one or more files and show on screen

-c is for character from first columns and -f for fields.
Example:
xyx:/>cut -c1,4 file1
ts
ts
ts
It is printing character of columns 1 and 4 of this file which contains t and s (part of this).

-c list cut the column positions identified in list.
-f list cut the fields identified in list.
-s used with -f to suppress lines without delimiters.
________________________________________

xyx:/>paste command merge the lines of one or more files into vertical columns separated by a tab.
xyx:/>paste file1 file2
This is a test file to compare the file contents This is a second test file to compare the file contents
This is a test file to compare the file contents This is a test file to compare the file contents
This is a test file to compare the file contents This is a test file to compare the file contents
This is a test file to compare the file contents This is a test file to compare the file contents
Let us take file1
this is firstline
and a file named testfile2 contains
this is testfile2
then running this command
paste testfile testfile2 > outputfile ##will put this into outputfile
this is firstline this is testfile2
it contains contents of both files in columns.
who | paste - - will list users in two columns.

Available imp Options:
-d'char' separate columns with char instead of a tab.
-s merge subsequent lines from one file.
________________________________________

xyx:/>sort command.
sort command sort the lines of a file or files, in alphabetical order. for example if you have a file named testfile with these contents
zzz
aaa
1234
yuer
wer
qww
wwe
Then running
> sort testfile
will give us output of

1234
aaa
qww
wer
wwe
yuer
zzz
Available Options:
-b ignores leading spaces and tabs.
-c checks whether files are already sorted.
-d ignores punctuation.
-i ignores non-printing characters.
-n sorts in arithmetic order.
-o file put output in a file.
+m[-m] skips n fields before sorting, and sort upto field position m.
-r reverse the order of sort.
-u identical lines in input file apear only one time in output.
________________________________________

xyx:/>uniq command.
uniq command removes duplicate adjacent lines from sorted file while sending one copy of each second file.
Examples

sort names | uniq -d will show which lines appear more than once in names file.
Available Options:
-c print each line once,
-d print duplicate lines once, but no unique lines.
-u print only unique lines.
________________________________________
xyx:/>awk and nwak command.
awk is more like a scripting language builtin on all unix systems. Although mostly used for text processing, etc.

Examples: to show total space in your system

xyz:/>df -t | awk 'BEGIN {tot=0} $2 == "total" {tot=tot+$1} END {print (tot*512)/1000000}'

Here the output of command df -t is being passed into awk which is counting the field 1 after pattern "total" appears. Same way if you change $1 to $4 it will accumulate and display the addition of field 4 which is used space.
________________________________________

xyx:/>sed command.
sed command launches a stream line editor which are used at command line.
you can enter your sed commands in a file and then using -f option edit your text file. It works as
sed [options] files
Available options:
-e 'instruction' editing instruction to the files.
-f script set of instructions from the editing script.
-n suppress default output.
_______________________________________

xyx:/>vi editor.
vi command launches a visual editor. vi editor is a default editor of all Unix systems. It has several modes. In order to write characters you will need to hit i to be in insert mode and then start typing. Make sure that your terminal has correct settings, vt100 emulation works good if you are logged in using pc.
Once you are done typing then to be in command mode where you can write/search/ you need to hit
Examples:-
Case I. To edit a file type
vi filename
:w filename to write
Case II. In case you are done writing and want to exit
:w! will write and exit.
Available options:
i for insert mode.

I inserts text at the cursor
A appends text at the end of the line.
a appends text after cursor.
O open a new line of text above the cursor.
o open a new line of text below the cursor.

: for command mode
to invoke command mode from insert mode.
:!sh to run unix commands.
x to delete a single character.
dd to delete an entire line
ndd to delete n number of lines.
d$ to delete from cursor to end of line.
yy to copy a line to buffer.
P to paste text from buffer.
nyy copy n number of lines.
:%s/string A/string B /g to replace string A with string B in whole file.
G to go to last line in file.
1G to go to the first line in file.
w to move forward to next word.
b to move backwards to next word.
$ to move to the end of line.
J join a line with the one below it.

/string to search string in file.
n to search for next occurrence of string.

Monday, November 29, 2010

Learning UNIX - I

UNIX commands to Explore
xyx:/>pwd command. Show home directory on screen, PWD means print working directory.
/export/home/crk
is output for the command when used pwd in /export/home/crk directory.
________________________________________

xyx:/>mkdir command.
xyx:/>mkdir crk will create new directory, i.e. here crk directory is created.
________________________________________

xyx:/>cd command.
cd crk will change directory from current directory to crk directory.
________________________________________

xyx:/>cat command
cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).
________________________________________

xyx:/>head command.
head filename by default will display the first 10 lines of a file. For first 50 lines you can use head -50 filename.
xyz:/> head -50 file1
________________________________________

xyx:/>tail command.
tail filename by default will display the last 10 lines of a file. For last 50 lines then you can use tail -50 filename.
________________________________________

xyx:/>more command. more command will display a page at a time and then wait for input which is spacebar. For example if you have a file which is 500 lines and you want to read it all. So you can use
more filename
________________________________________

xyx:/>wc command
wc command counts the characters, words or lines in a file depending upon the option.
Available Options
wc -l filename will print total number of lines in a file.
wc -w filename will print total number of words in a file.
wc -c filename will print total number of characters in a file.
________________________________________

xyx:/>man command. This is help command for looking any information about that command available,
man cp show cp command details with example and how you can use it.
man -k pattern command gives search for particular pattern with details.
________________________________________

xyx:/>banner command. For printing poster type ascii character, useful for making identifiable logins, any presentable output. Like below

xyx:/> banner crk

#### ##### # #
# # # # # #
# # # ####
# ##### # #
# # # # # #
#### # # # #

________________________________________

xyx:/>cal command. shows the calander on current month by default.
Witout options with cal command , will show current month calander, refer below example for more clarification

xyz:/>cal

November 2010
S M Tu W Th F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

N.B: if want to print calendar of 2nd Month of 2008
xyz> cal 2 2008
February 2008
S M Tu W Th F S
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29
________________________________________

xyx:/>ls command
ls command is most widely used command and it displays the contents of directory.
options
ls list all the files in your home directory.
ls -l list all the file names, permissions, group, in long format.
ls -a list all the files including hidden files that start with .
ls -lt list all files names based on the time of creation, newer first.
ls –Fx list files and directory names will be followed by slash.
ls -R lists all the files and files in the all the directories, recursively.
ls -R | more will list all the files and files in all the directories, one page at a time.
________________________________________

xyx:/>file Command displays about the contents of a given file, whether it is a text (Ascii) or binary file. To use it type
file filename. For example I have cal.txt which has ascii characters about calander of current month and I have resume1.doc file which is a binary file in MS word. Result would be as

file resume.doc
resume1.doc: data
file cal.txt
cal.txt: ascii text
________________________________________

xyx:/>cp command.
cp command copies a file. If I want to copy a file named oldfile in a current directory to a file named newfile in a current directory.

xyz:/>cp oldfile newfile

To copy oldfile to other directory in /tmp
xyz:/>cp oldfile /tmp/newfile.
Available Options are :
cp are -p and -r . -p options preserves the modification time and permissions,
-r recursively copy a directory and its files, duplicating the tree structure.
________________________________________

xyx:/>rcp command.
rcp command will copy files between two unix systems and works just like cp command (-p and -i options too).
Let us assume a unix system that is called unix1 and want to copy a file which is in current directory to a system that is called unix2 in /usr/om/ directory then you can use rcp command
rcp filename unix2:/usr/om
You will also need permissions between the two machines. For more infor type man rcp at command line.
________________________________________

xyx:/>mv command.
mv command is used to move a file from one directory to another directory or to rename a file.
Some examples:
mv oldfile newfile will rename oldfile to newfile.
mv -i oldfile newfile for confirmation prompt.
mv -f oldfile newfile will force the rename even if target file exists.
mv * /usr/om/ will move all the files in current directory to /usr/om directory.
________________________________________

xyx:/>ln command.
Instead of copying you can also make links to existing files using ln command.
If you want to create a link to a file called myfile in /usr/local/bin directory then you can enter this command.
ln myfile /usr/local/bin/myfile
Some examples:
ln -s fileone filetwo will create a symbolic link and can exist across machines.
ln -n option will not overwrite existing files.
ln -f will force the link to occur.
________________________________________

xyx:/>rm command.
To delete files use rm command.
Available Options:
rm oldfile will delete file named oldfile.
rm -f option will remove write-protected files without prompting.
rm -r option will delete the entire directory as well as all the subdirectories, very dangerous command.
________________________________________

xyx:/>rmdir command. Remove directory or directories if a directory is empty.
• rmdir om --> to remove om directory.
• rmdir -p --> to remove directories and any parent directories that are empty.

Wednesday, November 24, 2010

General Interview Questions

1) Tell me about yourself.
Ans: This is regular basic question asked in interviews. Try to brief about yourself as short as possible, do not describe the history of your family or town from where you are coming.
Present it in very simple manner which would give positive impression on other person. You can use the following:

- Your name (may include hometown details and parent's details)
- You education details (be short)
- Your employers, experience
- Your achivements, certifications

2) Tell me about some of the recent projects you have worked with?
Ans: Brief about recent projects (which are listed in Resume) you have worked on. Also is imperative that during your briefing, you demonstrate how you applied your skills and knowledge in the project.

3) Why are you leaving your current position?
Ans:Do not criticize your previous employer or coworkers or sound too opportunistic. It is fine to mention a major problem like a buy out, budget constraints, merger or liquidation.
You may also say that your chance to make a contribution is very low due to company wide changes or looking for a more challenging senior or designer role.

4) What do you like and/or dislike most about your current and/or last position?
Ans: The interviewer is trying to find the compatibility with the open position. So
Try Not to mention:
- You dislike overtime.
- You dislike management or coworkers etc.

You could use the following:
- You like challenges.
- Opportunity to grow into design, architecture, performance tuning etc.
- You dislike frustrating situations like identifying a memory leak problem or a complex transactional or a concurrency issue. You want to get on top of it as soon as possible.

5) What are your strengths and weaknesses?

Ans:
Strengths:
- Focus on Customer Staisfaction
- Taking initiatives and being pro-active: You can illustrate how you took initiative to fix a transactional issue,a performance problem or a memory leak problem.
- Team work and collabration, quick responsive
- Approachable for any issues
- Problem solving skills: Explain how you will break a complex problem into more manageable sub-sections and then apply brain storming and analytical skills to solve the complex problem.
- Open Communication: Always willing to listen to new ideas, or to adopt alternative approaches
- Communication skills: Illustrate that you can communicate effectively with all the team members, business analysts, users, testers, stake holders etc.
- Ability to work in a team environment as well as independently: Illustrate that you are technically sound to work independently as well as have the interpersonal skills to fit into any team environment.
- Hard working, honest, and conscientious etc are the adjectives to describe you.

Weaknesses:
Select a trait and come up with a solution to overcome your weakness. Stay away from personal qualities and concentrate more on professional traits for example:
- I pride myself on being an attention to detail guy but sometimes miss small details. So I am working on applying the 80/20 principle to manage time and details. Spend 80% of my effort and time on 20% of the tasks, which are critical and important to the task at hand.
- Some times when there is a technical issue or a problem I tend to work continuously until I fix it without having a break. But what I have noticed and am trying to practise is that taking a break away from the problem and thinking outside the square will assist you in identifying the root cause of the problem sooner.

6) Miscellaneous instructions:
- Try to find out the needs of the project in which you will be working and the needs of the people within the project. Try to get Business flow and basic architecture or request flow of recent project(s)
- Most of the interview questions are based on your own resume. So include only those things which you feel you can answer confident
- Where possible briefly demonstrate how you applied your skills/knowledge in the key areas and handled situations in your own way
- Always be honest to answer technical questions, you are not expected to remember or know everything in your area
- Do not be critical, focus on what you can do. Also try to be humorous to show your elegance
- Do not act superior or arrogant

Thursday, March 11, 2010

Windows Service

1)Installing Weblogic Server as a Windows Service:

Steps:

Create a batch file (.bat format) with the following script in the domain directory to Start WLS as a windows service and run this batch file through the command prompt.

Syntax:
---------------------------------------------------
SETLOCAL
set DOMAIN_NAME=
set USERDOMAIN_HOME=
set SERVER_NAME=
set JAVA_HOME=
call “
ENDLOCAL
---------------------------------------------------

For Example:
---------------------------------------------------
SETLOCAL
set DOMAIN_NAME= MyDomain
set USERDOMAIN_HOME= C:\bea101\user_projects\domains\MyDomain
set SERVER_NAME=AdminServer
set JAVA_HOME= C:\bea-WL-Server100\jdk150_11
call "C:\bea101\wlserver_10.0\server\bin\installSvc.cmd"
ENDLOCAL
---------------------------------------------------
After running this script in the command prompt you will observe a statement such as
“beasvc Server installed” When you observe in the windows services you will find the Admin server as installed and now start the service.

2)Procedure for Uninstalling Weblogic Admin Server as a Windows Service

Steps:

Create a batch file (.bat format) with the following script in the domain directory to Stop WLS as a windows service and run this batch file through the command prompt.
---------------------------------------------------
SETLOCAL
set WL_HOME=
rem *** Uninstall the service
"%WL_HOME%\server\bin\beasvc" -remove -svcname:"beasvc %DOMAIN_NAME%_%SERVER_NAME%"
ENDLOCAL
---------------------------------------------------

For Example:
---------------------------------------------------
SETLOCAL
set WL_HOME= C:\bea101\wlserver_10.0
rem *** Uninstall the service
"%WL_HOME%\server\bin\beasvc" -remove -svcname:"beasvc %DOMAIN_NAME%_%SERVER_NAME%"
ENDLOCAL
---------------------------------------------------
After running this script in the command prompt you will observe a statement such as
“beasvc _ removed”
When you observe in the windows services you will find that the Admin server is uninstalled.
------------------------------------------------------------------------------------------------------------


3)Steps to change the server mode from production to development when started as windows service:

Step1: Open regedit from “run” window

Step2: Go to HKEY_LOCAL_MACHINE -> SYSTEM -> CurrentControlSet -> Services -> -> Parameters -> CmdLine

Step3: Copy the value of CmdLine key to notepad

Step4: Modify -Dweblogic.ProductionModeEnabled to -Dweblogic.ProductionModeEnabled=false

Step5: Paste it back to CmdLine key

Step6: Save it & restart the server.

Memory

1)java.lang.OutOfMemoryError: PermGen space

Information related to the perm space:
The permanent generation is the area of heap that holds all the reflective data of the virtual machine itself, such as class and method objects (also called “method area” in The Java Virtual Machine Specification).
If an application loads “too many” classes then it is possible it will abort with an OutOfMemoryError.

The specific error is: “Exception in thread XXXX java.lang.OutOfMemoryError: PermGen space”.
The JVM itself needs memory to be able to run your application.
The PermGen is information about the classes that make up your application. Web applications and Servlet containers often need more PermGen memory than the JVM defaults to be able to run.
Fixing the java.lang.OutOfMemoryError: PermGen space error: Start your JVM with -XX:MaxPermSize=XXXm where XXX is a number like 256. This will allow the JVM to allocate XXX megabytes of memory for the PermGen space if that space is needed.

2)Information related to determining Memory Requirements:
How do I determine how much memory I need?
Weblogic recommends that you install a minimum of 256 MB of memory for each machine running Weblogic Server that will be handling more than minimal capacity.
If you are expecting a very heavy load then you increase your memory substantially.
A Weblogic Server deployment tracks session objects in memory, either to RAM or swapping to disk. There must be sufficient RAM/disk to store all the session objects. This RAM is accessible to Java through the Java heap.
Out of memory in java heap:
JVM throws java out of memory (java OOM) error if it is not able get more memory in java heap to allocate more java objects. The JVM cannot allocate more java objects if the java heap is full of live objects and it is not able to expand the java heap anymore.

In this situation, the JVM lets the application decide on what to do after throwing the java.lang.OutOfMemoryError.
For example, the application may handle this error and decide to shut down itself in a safe way or decide to run ignoring this error. If the application doesn’t handle this error, then the thread that throws this error will exit (you will not see this thread if you take a java thread dump).

In case of Weblogic server, this error is handled if it is thrown by an execute thread and the error is logged. If this error is being thrown continuously, then the core health monitor thread shuts down the Weblogic server.

Steps to follow in case of java OOM
a) Increase the java heap - Try increasing the java heap to see whether that solves the problem.
b) Caching in the application - If the application caches java objects in memory, then we should make sure that this cache is not growing constantly. There should be a limit for the number of objects in the cache. We can try reducing this limit to see if it reduces the java heap usage.

Java soft references can also be used for data caching as softly reachable objects are guaranteed to be removed when the JVM runs out of java heap.
c) Long living objects - If there are long living objects in the application, and then we can try reducing the life of the objects if possible. For example, tuning HTTP session timeout will help in reclaiming the idle session objects faster.
d) Add ‘-verbosegc’ flag in the java command line - This will print GC activity info to stdout/stderr. Redirect the stdout/stderr to a file. Run the application until the problem gets reproduced.

Make sure that the JVM does the following before throwing java OOM
Full GC run: Does a full GC and all the un-reachable, phantomly, weakly and softly reachable objects are removed and those spaces are reclaimed.
We can check whether full GC was done before the OOM message. A message like this is printed when a full GC is done (format varies depending on the JVM – Check JVM help message to understand the format)
[memory ] 7.160: GC 131072K->130052K (131072K) in 1057.359 ms
The format of the above output is (I will stick to the same format throughout this document) :
[memory ] : GC K->K (K), ms
[memory ] - start time of collection (seconds since jvm start)
[memory ] - memory used by objects before collection (KB)
[memory ] - memory used by objects after collection (KB)
[memory ] - size of heap after collection (KB)
[memory ] - total time of collection (milliseconds)
e) Memory leaks – One example of memory leak is when using database connection pools in application server. When using connection pools, the JDBC statement and resultset objects must be explicitly closed in a finally block.

This is due to the fact that calling close() on the connection objects from pool will simply return the connection back to the pool for re-use and it doesn’t actually close the connection and the associated statement/resultset objects.
It is recommended to follow the coding practices suggested in the following URLs to avoid memory leaks in your application.
http://download-llnw.oracle.com/docs/cd//E13222_01/wls/docs103/jdbc/troubleshooting.html

3)Information related to modifying the classpath:

After installation, Weblogic Server’s classpath is already set, but you may choose to modify it for a number of reasons such as adding a patch to Weblogic Server, updating the version of PointBase you are using, or adding support for Log4j logging.

To apply a patch to ALL of your Weblogic Server domains without the need to modify the classpath of a domain, give the patch JAR file the name, weblogic_sp.jar, and copy it into the WL_HOME/server/lib directory. The commEnv.cmd/sh script will automatically include a JAR named weblogic_sp on the classpath for you.

If you would rather not use the name weblogic_sp.jar for your patch file or you would just like to make sure a JAR file, such as one mentioned below, comes before weblogic.jar on the classpath:

* For ALL domains, edit the commEnv.cmd/sh script in WL_HOME/common/bin and prepend your JAR file to the WEBLOGIC_CLASSPATH environment variable.
* To apply a patch to a SPECIFIC Weblogic Server domain, edit the setDomainEnv.cmd/sh script in that domain’s bin directory, and prepend the JAR file to the PRE_CLASSPATH environment variable.

JConsole

Steps to use JConsole on remote process:

1) Add the following command in Weblogic server startup script:
-Dcom.sun.management.jmxremote

2) Enable Anonymous User under /Security

3) Enable IIOP under Servers//Protocols/IIOP

4) Provide user-name and password for IIOP under advance options

For JConsole:

a) In the JConsole window, select Connection > New Connection.

b) In the Connect to Agent window, select the Advanced tab.

c) On the Advanced tab, in the JMX URL box, enter:

service:jmx:rmi:///jndi/iiop://host:port/weblogic.management.mbeanservers.runtime

Where host:port is the host name and port of the Weblogic Server instance that hosts your MBeans.

For example:
service:jmx:rmi:///jndi/iiop://localhost:7001/weblogic.management.mbeanservers.runtime

d) In the User Name and Password boxes, enter the default IIOP user name and password.
e) Click Connect.

Reference URLs: http://download.oracle.com/docs/cd/E13222_01/wls/docs103/jmxinst/accesscust.html
http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html

Weblogic workshop

1)Weblogic workshop debug flags:


Two ways to enable more logging for IDE:

a) Workshop.exe internally invokes workshop.cfg file, which is present in the {BEAHOME}\weblogic81\workshop directory. This file by default uses javaw, which suppresses the command window for the IDE process. Modifying this to use java instead causes the command window to appear. This window enables users to take a thread dump of the IDE process. This can be done by hitting Ctrl - Break on the command window.

b) Another option is to enable logging for the IDE. This can be done by adding the following entry to the workshop.cfg file.
-Dworkshop.enablelogging=true
sample workshop.cfg file

D:\bea\8platsp2\weblogic81\workshop
D:\bea\8platsp2\jdk141_05\jre\bin\java.exe
-XX:-UseThreadPriorities -Xmx256m -Xms64m -Xss256k -Dworkshop.enablelogging=true -client -Dsun.java2d.noddraw=true -Dsun.java2d.d3d=false - Djava.system.class.loader="workshop.core.AppClassLoader" -cp "D:\bea\8platsp2\weblogic81\workshop\wlw-ide.jar" workshop.core.Workshop

2) Process to take thread dumps on Workshop:

By default the Workshop.cfg file, which is used by the Workshop.exe file in the //workshop directory, uses javaw.exe to start the IDE process.

Changing this to java.exe will open an additional shell window along with the IDE itself, which will show the debug messages generated by the process.

Pressing a Ctrl-Break on this shell window on Windows, or doing a 'kill -3' for the IDE process on Linux, will throw a thread dump for the process on the shell window.

3) Steps to initialize all the plugins in Weblogic Workshop:

Step1: Stop the workshop (if it running)

Step2: Go to command prompt

Step3: Move to %workshopHome% directory where you find workshop.exe file

Step4: Run the following command

>Workshop.exe –clean –initialize

Step5: Start the workshop

>Workshop.exe