UNIX Shell Scripting

Below are the most commonly used Unix  / Shell scripting commands.

VI Editor

:q  ———————————-> QUIT

:q! ———————————->  QUIT WITHOUT SAVING

:w ———————————> Save

:wq ——————————–> save and quit

:w fileName ——————————> save as fileName

These are in Command mode:

 

Syntax:

 

[Count] command [where]

 

---> delete character under the cursor.

X --->  Delete the character before the cursor.

u--> Undo,

D-> Delete till the end of the line

i --> Insert

a --> Append

r --> Replace the word under the cursor

R --> Replace everything (overwrite text)

 

 

 

 

It cuts the data in command mode

 

d^       deletes from current cursor position to the beginning of the line.

d$       deletes from current cursor position to the end of the line.

dw      deletes from current cursor position to the end of the word.

dd       deletes 1 lines from current cursor position downwards

3dd     deletes three lines from current cursor position downwards.

 

 

Y–> Yank (copy) the current line.

P -> Paste the line

dd  –> It will cut the line, so that you can paste it with “P”

:/word_to_search (searches from top to bottom)

:?word_to_search (searches from bottom to top)

N -> repeat the last search given by “:/” or “:?”

n —> Move the cursor to the next match

:set nu —> will display line numbers in VI editor.

:set nonu  > Hide line numbers

:set wm=3  ——-> sets the warpmargin to be three characters from the right of  the screen. This gives me a nice wordwrap.

: set sm    ———> The second line sets showmatch so that whenever I type a }, ) or ], it shows the matching brace, parenthesis, or bracket. This is useful for the programming I do.

:set ic ——–>  Set Ignore Case during searches.

:set ai ——–>  Set Auto Indentation during text entry.

 

End of the file in VI editor-à G

Beginning of the file in VI editor à 1G (or gg)

Go to 10th line of the file in VI editor —-à 10G

 

$—à end of the current line in Vi

^—à beginning of the current line in vi

 

:Line_number  –à Cursor will go to that line.

 

 

*

:x<Return> quit vi, writing out modified file to file named in original invocation

 

:wq<Return> quit vi, writing out modified file to file named in original invocation

 

:q<Return> quit (or exit) vi

*

:q!<Return> quit vi even though latest changes have not been saved for this vi call

    

Vim editor

It will show the shell script code in color.

Example:

vim test.sh

To change the colors, do :

Escape —à “:” —à colorscheme —-à space tab (It will show the possible colors)

Selecting default will take you back.

Use vi shortcuts in terminal

Many Unix shells (bash, zsh, etc.) come with keyboard shortcuts enabled: C-a jumps to the start of the line, C-e jumps to the end, and so on. However, these are taken from Emacs. It’s possible to tell your shell to use Vi shortcuts instead. Not only will the keybindings match what you’re used to, but you’ll also have modal editing, just like Vi.

To enable Vi-mode, edit (or create) the file ~/.inputrc or /etc/inputrc and add the following lines:

set editing-mode vi

set keymap vi-command

Searching in vi or vim editor

Escape –à / –à search_string. ( It will highlight the first search_string)

You can move to the next one by pressing the “n” button.

TO SEE THE CRON SCRIPTS

crontab –l

TO EDIT THE CRONS

crontab –e  (IT will open in a VI editor, once you edit it and save, it will install the new crontab, it automatically means you configured crontab)

# .—————- minute (0 – 59)

# |  .————- hour (0 – 23)

# |  |  .———- day of month (1 – 31)

# |  |  |  .——- month (1 – 12) OR jan,feb,mar,apr …

# |  |  |  |  .—- day of week(0-6)(Sunday=0 or 7)OR sun,mon,tue,wed,thu,fri,sat

# |  |  |  |  |

# *  *  *  *  * user-name  command to be executed

Special String for Cron

# Names can also be used for the month and week day fields.  Use the first three

# letters of the particular day or month (case doesn’t matter).  Ranges or

# lists of names are not allowed.

#

# @reboot    :    Run once, at startup.

# @yearly    :    Run once a year, ie.  “0 0 1 1 *”

# @annually  :    Run once a year, ie.  “0 0 1 1 *”

# @monthly   :    Run once a month, ie. “0 0 1 * *”

# @weekly    :    Run once a week, ie.  “0 0 * * 0”

# @daily     :    Run once a day, ie.   “0 0 * * *”

# @hourly    :    Run once an hour, ie. “0 * * * *”

#

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

Character / Word substitution

Syntax of the text substitution inside vim editor:

:[range]s[ubstitute]/{pattern}/{string}/[flags] [count]

Example: %s/13105/13205/g

Following are three possible flags.

  1. [c] Confirm each substitution.
  2. [g] Replace all occurrences in the line.
  3. [i] Ignore case for the pattern.

This is the basic fundamental usage of the text substitution inside VI editor. When you want a specific text to be replaced with another text in the entire file then you can use the following sequence.

: %s/old-text/new-text/g

  • %s – specifies all lines. Specifying the range as ‘%’ means do substitution in the entire file.
  • g – Specifies all occurrences in the line. With the ‘g’ flag, you can make the whole line to be substituted. If this ‘g’ flag is not used then only first occurrence in the line only will be substituted.

Use: “sh –x” to run the script in Debug Mode

To run the script in debug mode

Ex :

sh -x tibemsadmin_wrapper.ksh -e prod

Linux and Unix wc command

wc [-c | -m | -C ] [-l] [-w] [ file … ]

-c Count bytes.
-m Count characters.
-C Same as -m.
-l Count lines.
-w Count words delimited by white space characters or new line characters. Delimiting characters are Extended Unix Code (EUC) characters from any code set defined by iswspace()
file Name of file to word count.

UNIX search and kill process on unix/linux box

kill $(ps -ef | grep tibco | grep tibemsadmin | grep EMS_QUERY_INFO_TMP | awk ‘{print $2}’)

Above will search for this command “ps -ef | grep tibco | grep tibemsadmin | grep EMS_QUERY_INFO_TMP”, and then kills the returned processes.

To do Telnet from one UNIX box to another

telnet host_name 3520

(It is to check if you are able to connect from current box to the remote box on a particular PORT            )

Nslookup

nslookup is a network administration command-line tool available for many computer operating systems for querying the Domain Name System (DNS) to obtain domain name or IP address mapping or for any other specific DNS record.

The name nslookup means name server lookup. Nslookup uses the operating system’s local Domain Name System resolver library to perform its queries. Thus, it is configured automatically by the contents of the operating system file resolv.conf.[1]

Example:

nslookup host_name

nslookup host_name

PING Command

Use the ping command to test the connection between the local server and a remote UNIX server. The ping command sends ICMP Echo Request (ECHO_REQUEST) packets to the host once per second. Each packet that is echoed back via an ICMP Echo Response packet is written to the standard output, including round-trip time.

Syntax

ping serverName
ping ServerIPAddress
ping 192.168.1.2
ping yahoo.com
ping server.cyberciti.biz

Netstat Command

To see which application is using which port, you can use this command.

netstat.exe –a –n –o.  The switches we are using provide the following:

  • -a: listing of all connections and listening ports
  • -n: display address and port numbers in numerical form
  • -o: display the owning PID associated with each connection

id Command

“id” will print the user ID and other details.

In Unix, how do I find a user’s UID or GID?

To find a user’s UID or GID in Unix, use the id command. To find a specific user’s UID, at the Unix prompt, enter:

id -u username

Replace username with the appropriate user’s username. To find a user’s GID, at the Unix prompt, enter:

id -g username

If you wish to find out all the groups a user belongs to, instead enter:

id -G username

If you wish to see the UID and all groups associated with a user, enter id without any options, as follows:

id username

Initialization files for each shell

Shell Profile File
Ksh .profile
Bourne .profile
Bash .bash_profile
Tcsh .login
Csh .login

LS command

Syntax :

ls [OPTION]… [FILE]…

Ls –ltr              SHOW THE LAST MODIFEID AT THE END.

LS –a               SHOW THE HIDDEN FILES.

Ls –ld */           SHOW ONLY THE DIRECTORIES.

Ls -1                list one file per line.

Ls –ld              Gives information about the current directory (.)

-t     sort by modification time

-r,    reverse order while sorting

-l    Long listing

-c, Use time of last modification of the i-node (file created, mode changed, and so forth) for sorting (-t) or printing (-l or -n).

-u Use time of last access instead of last modification for sorting (with the -t option) or printing (with the -l option).

ls – – color=auto           (Recognizing the file type by the color in which it gets displayed is an another kind in   classification of file)

-a,   do not hide entries starting with.

-S   do the sort by file size.

-X, Sort by extension

U, None or no sorting

version -v

status -c,

atime -u, access -u, use -u

Chmod

$ chmod -R 751 directory-name/   ——à Use option -R to change the permission recursively as shown below.

    Type (File Type) ——– U (User) ————- G (Group)    ———–O (Others)

– (normal file)               rwx                            rwx                            rwx

L (Link file)

S (Socket file)

D (Directory)

Chown (change owner)

The chown command (abbreviation for change owner) is used on Unix-like systems to change the owner of a file. In most implementations,[citation needed] it can only be executed by thesuperuser, to prevent users simply changing ownership of files that aren’t their’s to access them. Unprivileged (regular) users who wish to change the group of a file that they own may use chgrp.

Syntax

chown [-R] newowner filenames

-R Change the permission on files that are in the subdirectories of the directory that you are currently in.
newowner The alias/username of the new owner of the file.
filenames The file that you are changing the rights to.

Echo $SHELL —à This will give the shell name that you are using.

Folder Navigation on UNIX environments

~ ——————————————à Home Directory

~ username              —————————————————–à       User name Home Directory

cd /                            ———————————————-à moves to root directory

cd ..                 ————————————–à  Moves you one level up the directory tree structure

!                              ————————————————à Command History

 Cd –                    ———————————————–à to toggle between the last two directories.

$# Number of arguments to script
$* Arguments to script
$@ Original arguments to script
$- Flags passed to shell
$? Status of previous command
$$ Process identification number
$! sh PID of last background job


$$ expands to the process id of the shell innovated to run the script. Useful for creating unique temporary filenames relative to this instantiation of the script.

You can use the “$$” to get the shell you are on, like this

Ps –p $$

 

In Unix you can set the Java PATH and JAVA CLASSPATH environment variables like below.

Q. How do I add new path to PATH variable under Linux and UNIX operating system?

A. The syntax for setting path under UNIX / Linux dependent on which shell you are using.

BASH / SH shell uses following syntax:
export PATH=$PATH:/path/to/dir1:/path/to/dir2

For tcsh or csh, shell enter:
set PATH = ($PATH /path/to/dir1 /path/to/dir2)

Example :

PATH=/opt/java/jdk1.6.0_22/bin:$PATH

export PATH

export CLASSPATH=.:/export/home/userID/JavaClient/*

(This will put all the jars in the folder JavaClient/* to the classpath)

 

df (disk free)

df displays the amount of disk space available on the file system containing each file name argument.  If no file name is given, the space available on all currently mounted file systems is shown.  Disk space is shown in 1K blocks by default, unless the environment variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used.

Report how much free disk space is available for each mount you have and the local file system.

This will display information about all the file systems (Both local and mounted)

EX : df -h

To get the information for a particular file system, mention the file system.

df –h (human readable format)

The above command is one of the most commonly used commands as it displays the sizes in an easy to read format as shown in the below example.

df –i (inode information)

list inode information instead of block usage

df –l (just show the local file system details, not the mounted disk details)

To know if the folder you are in is mounted or not.

du command (du – estimate file space usage)

Summarize disk usage of each FILE, recursively for directories.

Tells you how much space a file occupies.

du [-a] [-k] [-s] [-d] [-L] [-o] [-r] [-x] directories

ex : du –sh *   (it will print the (size)sum of each folder or file in the current folder )

ex : du –sh .   ( It will print the sum of the folder size)

-a     Displays the space that each file is taking up.

-k     Write the files sizes in units of 1024 bytes, rather than the default 512-byte units.

-s     Instead of the default output, report only the total sum for each of the specified files.

-d     Do not cross filesystem boundaries. For example, du -d / reports usage only on the root partition.

-L     Process symbolic links by using the file or directory which the symbolic link references, rather than the link itself.

-o     Do not add child directories’ usage to a parent’s total. Without this option, the usage listed for a particular directory is the space taken by the files in that directory, as well as the files in all directories beneath it. This option does nothing if -s is used.

-r     Generate messages about directories that cannot be read, files that cannot be opened, and so forth, rather than being silent (the default).

-x     When evaluating file sizes, evaluate only those files that have the same device as the file specified by the file operand.

Directories        Specifies the directory or directories.

Special directories

. current directory, eg /home/kim/./ is /home/kim/,
eg ls . is the same as ls
.. parent directory, eg /home/kim/../ is /home,
eg if you are in /home/kim ls .. will show you /home
.abc files beginning with “.” are not show by default, use ls -a to see
/ paths starting with / are absolute, and do not depend on the current directory
./foo  paths which do not start with / are relative, eg ../foo.py, or subdir/bar.py

 

About pgrep and pkill

The pgrep utility examines the active processes on the system and reports the process IDs of the processes whose attributes match the criteria specified on the command line.

How To Use grep Command In Linux / UNIX

grep command searches the given file for lines containing a match to the given strings or words. By default, grep prints the matching lines. Use grep to search for lines of text that match one or many regular expressions, and outputs only the matching lines.

The name, “grep”, derives from the command used to perform a similar operation, using the Unix/Linux text editor ed:
g/re/p

grep command syntax

grep ‘word’ filename

grep ‘string1 string2’  filename

cat otherfile | grep ‘something’

command | grep ‘something’

 

$ grep boo /etc/passwd ——————à Search for boo in passed file.

$ grep -i “boo” /etc/passwd ————-à Case Sensitive search.

$ grep -r “192.168.1.5” /etc/ ———–à search recursively i.e. read all files under each     directory for a string “192.168.1.5”

$ grep -w “boo” /path/to/file ———–à Exact word (When you search for boo, grep will match fooboo, boo123, etc. You can force grep to select only those lines containing matches that form whole words i.e. match only boo word 🙂

$ egrep -w ‘word1|word2’ /path/to/file –à It will return lines that matches word1 or word2.

$ grep -c ‘word’ /path/to/file ———-à grep can report the number of times that the pattern has been matched for each file using -c (count) option:

$ grep -n ‘word’ /path/to/file ———-à Line number (Also note that you can use -n option, which causes grep to precede each line of output with the number of the line in the text file from which it was obtained:)

$ grep -v bar /path/to/file ————-à (INVERT) Return lines that don’t match. You can use -v option to print inverts the match; that is, it matches only those lines that do not contain the given word. For example print all line that do not contain the word bar:

gzip / gunzip

These commands are used to zip or unzip the files.

Echo $SHELL ——à THIS WILL PRINT THE SHELL YOU ARE NO

(SHELL LEVEL)

Echo $SHLVL ——à TH IS WILL PRINT THE SHELL LEVEL YOU ARE ON.

You can do “exit” to go one shell up.

In normal cases the default SHELL is bash.

more Display a file, or program output one page at a time.  Examples:

more mp3files.txt

ls -la | more

less An improved replacement for the “more” command. Allows you to scroll backwards as well as forwards.  To search do “/search_string”. For the next pattern do “n”

su “Switch User”. Allows you to switch to another user’s account temporarily. The default account to switch to is the root/superuser account.

Examples:

su – Switch the root account

su – – Switch to root, and log in with root’s environment

su larry – Switch to Larry’s account

nohup command

When working with the UNIX operating system, there will be times when you will want to run commands that are immune to log outs or unplanned login session terminations.  This is especially true for UNIX system administrators.  The UNIX command for handling this job is the nohup (no hangup) command.Normally when you log out, or your session terminates unexpectedly, the system will kill all processes you have started.  Starting a command with nohup counters this by arranging for all stopped, running, and background jobs to ignore the SIGHUP signal.

The syntax for nohup is:

nohup command [arguments]
You may optionally add an ampersand to the end of the command line to run the job in the background:
nohup command [arguments] &
If you do not redirect output from a process kicked off with nohup, both standard output (stdout) and standard error (stderr) are sent to a file named nohup.out.  This file will be created in $HOME (your home directory) if it cannot be created in the working directory.  Real-time monitoring of what is being written to nohup.out can be accomplished with the “tail -f nohup.out” command.Although the nohup command is extremely valuable to UNIX system administrators, it is also a must-know tool for others who run lengthy or critical processes on UNIX systems.

Unix Command Substitution (assign output of a command to the variable)

You need to use command substitution feature of bash. It allows you to run a shell command and store its output to a variable. To assign output of any shell command to variable in bash, use the following command

var=$(command-name-here)
var=$(command-name-here arg1)
var=$(/path/to/command)
var=$(/path/to/command arg1 arg2)

OR

var=`command-name-here`

var=`command-name-here arg1`

var=`/path/to/command`

var=`/path/to/command arg1 arg2`

Do not put any spaces after the equals sign and command must be on right side of =. See how to assign values to shell variables for more information.

Replace first letter of a string with different one

1)      Replace 3 at the start of the string with 1,

_ssl_port_=$(echo ${_PORT_} | sed ‘s/^3/1/’)

2)      Replace

Check if the string is starting with 3 or not

if [[ ${_PORT_:0:1} = “3” ]]

then

fi

tee command

 

Tee command is used to store and view (both at the same time) the output of any other command.

Tee command writes to the STDOUT, and to a file at a time as shown in the examples below.

The following command (with the help of tee command) writes the output both to the screen (stdout) and to the file.

$ ls | tee file

 

The following command will take a backup of the crontab entries, and pass the crontab entries as an input to sed command which will do the substituion. After the substitution, it will be added as a new cron job.

$ crontab -l | tee crontab-backup.txt | sed 's/old/new/' | crontab –

By default tee command overwrites the file. You can instruct tee command to append to the file using the option –a as shown below.

$ ls | tee –a file

You can also write the output to multiple files as shown below.

$ ls | tee file1 file2 file3

 

 

 

Syntax

tee [OPTION]… [FILE]…

-a
–append
Append to the given FILEs, do not overwrite.
-i ignore interrupt signals.
–help Display the help screen.
–version Display the version.

 

 

Linux / UNIX source Command Examples

The source command in shell is used to execute commands from a file in the current shell. This is useful to load function or variables stored in another file.

source command syntax

The syntax is as follows:

source filename

source /path/to/file

It will read and execute commands from given FILENAME in the current shell. The entries in $PATH are used to find the directory containing FILENAME.

period-Linux Command (Dot)

source or dot operator

Syntax: “dot” command [period].

. filename [arguments]

source filename [arguments]

Description: Equivalent to source. This command, when invoked from the command-line, executes a script. Within a script, a source file-name loads the file file-name. Sourcing a file (dot-command) imports code into the script, appending to the script (same effect as the #include directive in a C program). The net result is the same as if the “sourced” lines of code were physically present in the body of the script. This is useful in situations when multiple scripts use a common data file or function library.

In Unix, how can I find the current values of all my environment variables and functions?

To find the current values of all your environment variables and functions in UNIX, if you are using the sh, ksh, or bash shell, at the prompt, enter:

set

If you are using the csh or tcsh shell, enter:

printenv

The resulting lists show all environment variables (e.g., home, shell) and functions, and their values, both default and user-defined. On most systems, entering setenv will display the same results as printenv.

For more information about the printenv or set commands, at the Unix prompt, enter either of the following commands:

man printenv

man set

Common environment variables in Unix

Most well-known environment variables are the following:

  • USER – username of a Unix user
  • HOME – full path to a user’s home directory
  • TERM – terminal or terminal emulator used by a current user
  • PATH – list of directories searched for executable files when you type a command in Unix shell
  • PWD – current directory

Strings Checking

# Zero length Checking:             [[ -z “$s1” ]]

# Nonzero length checking:     [[ -n “$s1” ]]

Do “man test” to see all the string checking options

-d ———à to check if it is a directory or not.

Clear a File with /dev/null

Ways to clear a file.

1)      > cat /dev/null > file_tobe_cleared.log

2)      > cp /dev/null file_tobe_cleared.log

3)      > > file_tobe_cleared.log

Redirection in UNIX (> and <)

command1 > file1

executes command1, placing the output in file1. This will clobber any existing data in file1.

command1 >> file1

To append output to the end of the file, use the >> operator:

command1 < file1

executes command1, with file1 as the source of input (as opposed to the keyboard).

Handle

Name

Description

0 stdin Standard input
1 stdout Standard output
2 stderr Standard error

command1 2> file1

executes command1, directing the standard error stream to file1.

Purpose of init.d folder

/etc/Init.d/” folder contains the startup scripts, these scripts are invoked by the “init” process. “init” process will run the script “/etc/inittab/”, which will call processes in the folder “/etc/init.d/”.

 

Init

In Unix-based computer operating systems, init (short for initialization) is a daemon process that is the direct or indirect ancestor of all other processes. It automatically adopts all orphaned processes. Init is the first process started during booting, and is typically assigned PID number 1. It is started by the kernel using a hard-coded filename, and if the kernel is unable to start it, a kernel panic will result. Init continues running until the system is shut down.

Which

You can do this by using the which command, which will locate a command, if it exists, and tell you that it can’t locate it if it doesn’t. For example, to find out whether there are commands called dc and dac, type:

which dc
which dac

Writing UNIX Scripts

(http://www.calpoly.edu/~rasplund/script.html)

There are actually no less than three different types of scripts supported in Unix: Bourne shell, C shell, and Korn shell. Bourne is the most common, Korn the most powerful, and C the most C-like (handy for C programmers). This tutorial will concentrate on the simplest of the three: the Bourne shell.

#!/bin/sh
echo "hello world"

Comments and Commands

In the Bourne shell, any line beginning with a hash ‘#’ character in the first column is taken to be a comment and is ignored. The only exception is the first line in the file, where the comment is used to indicate which shell should be used (/bin/sh is the Bourne shell).

#!/bin/sh
# purpose: print out current directory name and contents
pwd
ls

The special variables $1-$9 correspond to the arguments passed to the script when it is invoked.

Shell Variables

#!/bin/sh
# name is a variable
name="fred"
echo "The name is $name"

Conditionals in Shell Scripts

#!/bin/sh

# show script

if [ -d $1 ]

then

ls $1

else

cat $1

fi

Here, we notice a number of points:

  • The if-statement begins with the keyword if, and ends with the keyword fi (if, reversed).
  • The if keyword is followed by a condition, which is enclosed in square brackets. In this case, the condition -d $1 may be read as: if $1 is a directory.
  • The line after the if keyword contains the keyword then.
  • Optionally, you may include an else keyword.

There are a number of conditions supported by shell scripts; for a complete list, use the on-line manual on the test command (man test). Some examples are: -d (is a directory?), -f (is a file?), = (are two strings the same?), -r (is string set?), -eq (are two numbers equal?), -gt (is first number greater than second?). You can also test whether a variable is set to anything, simply by enclosing it in quotes in the condition part of the if-statement. The script below gives an example:


Quoting in Scripts

Confusingly, in Shell scripts no less than three different types of quotes are used, all of which have special meanings. We have already met two of these, and will now consider all three in detail.

‘SAMPLE  TEXT’ ————-à IT WILL BE TRATED AS LITERAL TEXT. SHELL WILL NOT LOOK FOR ANY COMMANDS OR VARIABLES INSIDE THE QUOTOS.

“SAMPLE  TEXT” ————à IT WILL LOOK FOR VARIABLES INSIDE THE QUOTOS.

`SAMPLE TEXT`  ————-à IT WILL INTERPRET THE TEXT INSIDE THE QUOTOS AS COMMAND.

`    `   Command substitution   ————————à

This quotation mark is the back quote (more properly called backtick or grave) character: “`”. It looks like the single quote and sometimes people get them confused in shell scripts. The first two are used for quoting phrases in UNIX. The back quote is not used for quoting characters. That character is used for command substitution, where the characters between them are executed by the shell and the results is inserted on that line. Example:

% echo the date is `date`

Let’s get back to the UNIX quoting mechanisms. The three quoting mechanisms you can use are the single quote, and double quote, and the b

‘ ’        —————-à Strong Quotes ———–à

Inside the single quotes, you can include almost all meta-characters:

% echo 'What the *heck* is a $ doing here???'
What the *heck* is a $ doing here???

“   ”       ———-à Weak Quotes ——-à

one that doesn’t expand meta-characters like “*” or “?,” but does expand variables and does command substitution. This can be done with the double quote characters:

% echo "Is your home directory $HOME?"
Is your home directory /home/kreskin/u0/barnett?
% echo "Your current directory is `pwd`"
Your current directory is /home/kreskin/u0/barnett

Special shell variables

There are some variables which are set internally by the shell and which are available to the user:

$1 – $9       these variables are the positional parameters.

$0            the name of the command currently being executed.

$argv[20]     refers to the 20th command line argument

$#            the number of positional arguments given to this

invocation of the shell.

$?            the exit status of the last command executed is

given as a decimal string.  When a command

completes successfully, it returns the exit status

of 0 (zero), otherwise it returns a non-zero exit

status.

$$            the process number of this shell – useful for

including in filenames, to make them unique.

$!            the process id of the last command run in

the background.

$-            the current options supplied to this invocation

of the shell.

$*            a string containing all the arguments to the

shell, starting at $1.

$@            same as above, except when quoted :

“$*” expanded into ONE long element : “$1 $2 $3”

“$@” expanded into THREE elements : “$1” “$2” “$3”

shift   : $2 -> $1 …)

IF statement in UNIX scripting

If/Else

In order for a script to be very useful, you will need to be able to test the conditions of variables. Most programming and scripting languages have some sort of if/else expression and so does the bourne shell. Unlike most other languages, spaces are very important when using an if statement. Let’s do a simple script that will ask a user for a password before allowing him to continue. This is obviously not how you would implement such security in a real system, but it will make a good example of using if and else statements.

#!/bin/sh

# This is some secure program that uses security.

VALID_PASSWORD=”secret” #this is our password.

echo “Please enter the password:”

read PASSWORD

if [ “$PASSWORD” == “$VALID_PASSWORD” ]; then

echo “You have access!”

else

echo “ACCESS DENIED!”

fi

Remember that the spacing is very important in the if statement. Notice that the termination of the if statement is fi. You will need to use the fi statement to terminate an if whether or not use use an else as well. You can also replace the “==” with “!=” to test if the variables are NOT equal. There are other tokens that you can put in place of the “==” for other types of tests. The following table shows the different expressions allowed.

Comparisons:

-eq equal to
-ne not equal to
-lt less than
-le less than or equal to
-gt greater than
-ge greater than or equal to

File Operations:

-s file exists and is not empty
-f file exists and is not a directory
-d directory exists
-x file is executable
-w file is writable
-r file is readable

Check File Exists or Not

You need to use the test command to check file types and compare values. The same command can be used to see if a file exist of not. The syntax is as follows:

test -e filename

[ -e filename ]

test -f filename

[ -f filename ]

It is possible to do wildcard style string comparisons in Bash scripting.

string=’My string’;

if [[ “$string” == *My* ]]

then

echo “It’s there!”;

fi

needle=’y s’

if [[ “$string” == *”$needle”* ]]; then

echo “haystack ‘$string’ contains needle ‘$needle'”

fi

Break Statement in Korn Shell Scripting

break ——————à it in break the flow from the enclosed loop.

break 2  —————à It will break the flow from the 2nd enclosed loop.

TAR and encrypt with openssl

# tar -cf – directory | openssl DHE-RSA-AES256-SHA -salt -out directory.tar.aes      # Encrypt

Decrept with openssl and untar it

# openssl DHE-RSA-AES256-SHA -d -salt -in directory.tar.aes | tar -x -f –            # Decrypt

Executing a background job

Appending an ampersand ( & ) to the command runs the job in the background.

Sending the current foreground job to the background using CTRL-Z and bg command

You can send an already running foreground job to background as explained below:

  • Press ‘CTRL+Z’ which will suspend the current foreground job.
  • Execute bg to make that command to execute in background.

View all the background jobs using jobs command

You can list out the background jobs with the command jobs. Sample output of jobs command is

Taking a job from the background to the foreground using fg command

You can bring a background job to the foreground using fg command. When executed without arguments, it will take the most recent background job to the foreground.

# fg

If you have multiple background ground jobs, and would want to bring a certain job to the foreground, execute jobs command which will show the job id and command.

In the following example, fg %1 will bring the job#1 (i.e download-file.sh) to the foreground.

# jobs
[1]   Running                 bash download-file.sh &
[2]-  Running                 evolution &
[3]+  Done                    nautilus .
# fg %1

Kill a specific background job using kill %

If you want to kill a specific background job use, kill %job-number. For example, to kill the job 2 use

# kill %2


									
Posted in Unix

Tibco EMS

1)      Tibco EMS provides mechanisms for administering server operations and creating objects that are managed by the server, such as connection factories and destinations. EMS clients can retrieve references to these administered objects by using the JNDI.

2)      Tibco EMS provides the ability for servers to route the messages between each other. Topic messages can be routed across multiple hops, Queue messages can travel at most one hop to any other server from the server that owns the queue.

3)      Tibco EMS supports SSL. SSL is supported between the following componenets.

Between an EMS client and EMS server.
Between an administration tool and EMS server.
Between Routed Servers.
Between Fault-Tolerant servers.

4)      Tibco EMS allows you to work with third-party naming/directory service providers or with third-party application servers.

5)      Tibco EMS can integrate with Java Transaction API (JTA) compliant transaction managers.

6)      JMS messages have the standard structure.

Header  (required)

Properties (optional)

Body (optional)

JMS standard specifies two delivery modes, PERSISTENT and NON-PERSISTENT. Tibco EMS also includes RELIABLE_DELIVERY. RELIABLE_DELIVERY mode eliminates some of the over head associated with the other delivery modes.

Table 1 Summary of message properties (Sheet 1 of 2)

Property

Description

More Info

JMS_TIBCO_COMPRESS Allows messages to be compressed for more efficient storage. 65
JMS_TIBCO_DISABLE_SENDER Specifies that the user name of the message sender should not be included in the message, if possible. 68
JMS_TIBCO_IMPORTED Set by the server when the message has been imported from TIBCO Rendezvous. 86111
JMS_TIBCO_MSG_EXT Extends the functionality of map messages to include submessages or arrays. 69
JMS_TIBCO_MSG_TRACE Specifies the message should be traced from producer to consumer. 231
JMS_TIBCO_PRESERVE_UNDELIVERED Specifies the message is to be placed on the undelivered message queue if the message must be removed. 67
JMS_TIBCO_SENDER Contains the user name of the message sender. 68

7)      Sample Comments from Queues.conf file, provided by tibco, it explains the properties that we can set for each destination.

Example :

prv.tlgapi.addequipmentupgrade.request.spm2 failsafe,global,maxbytes=100MB,flowControl=90MB,prefetch=64,maxRedelivery=3,expiration=5min

prv.tlgapi.addequipmentupgrade.response.spm2 failsafe,global,maxbytes=100MB,flowControl=90MB,prefetch=64,maxRedelivery=3,expiration=5min

Queue and topic properties can be set when the destination is created. Queue and topic properties can add the following functionality.

  • A fail safe mode allows messages to be written to disk synchronously to guarantee no messages are ever lost due to server failure.
  • Enforcement of permissions can be set at the queue or topic level so that some destinations may require access control and others may not.
  • You can limit the size of messages stored on a queue. If a receiver is offline for a long time, queue messages can accumulate and consume machine resources.
  • You can limit the size of messages stored for durable topic subscriptions. If a subscriber is offline for a long time, topic messages can accumulate and consume machine resources.
  • Messages sent to destinations can be routed to other servers.
  • You can exchange messages with other message services. Queues can receive TIBCO Rendezvous and TIBCO SmartSockets messages. Topics can either receive or send Rendezvous and TIBCO SmartSockets messages.
  • Queues can be set to be exclusive or non-exclusive. Only one receiver can receive messages from an exclusive queue. More than one receiver can receive messages from non-exclusive queues.
  • Queues can specify a redelivery policy. When messages must be redelivered, you can specify a property on the queue that determines the maximum number of times a message should be redelivered.
  • All messages passing through a destination can be traced and logged.
  • The user name of message producer that sends messages can be included in the message.
  • TIBCO Enterprise Message Service allows you to create wildcard destinations. The wildcard destination name is the parent, and any names that match the wildcard destination name inherit the properties of the parent.

8)      Java applications use the javax.jms package to send and receive messages. It is a set of interfaces specified by the JMS standard for creating connection to the EMS server. Com.tibco.tibems package provides the tibco EMS specific aspects.

9)      There are 3 kinds of destinations.

1) Static Queues and topics (These destinations are created through the configuration files)
2) Dynamic Queues and Topics ( These are created on the fly by client applications)
3) Temporary Queues (Servers connected by Routes exchange messages sent to temporary        queues, as a result temporary queues are ideal for reply messages in request/reply interactions.)

Dynamic queues and topics inherit properties from their respective parents. When shown by the administration tool, properties of a queue or topic may have an asterisk (*) character in front of its name. This means that this property was inherited from the parent queue or topic and cannot be changed. For more information, refer to Inheritance of Properties and Wildcards * and >.

10)   Destination property Failsafe means: EMS provides 2 modes of persisting topic/queue messages to the external storage

normal (Writes all messages to the file on disk in asynchronous mode, data may remain in system buffers for a short time before it is written to disk, and may be lost when the software or hardware fails.)
failsafe (Failsafe mode writes data in synchronous mode, for cases where data loss is not acceptable this property should be set while creating the destinations. It affects the performance )

11)   Destination property secure means:  When secure property is enabled, it instructs the server to check user permissions whenever a user attempts to perform an operation on that destination.

The server authorization property acts as a master switch for checking permissions. That is, the server checks user permissions on secure destinations only when the authorization property is enabled. To enforce permissions, you must both enable the authorization configuration parameter, and set the secure property on each affected destination.

12)   Destination property maxbytes means : topics and queues can specify maxbytes property in the form: maxbytes=b, where  b is the number of bytes.

for queues, maxbytes defines the maximum size (in bytes) that the queue can store, summed over all the messages in the queue.

for topics, maxbytes limits the maximum size that the topic store for delivery to each durable subscriber on the topic.

13)   Destination property maxMsgs means : Queues can specify maxMsgs property in the form maxmsgs=m, where m is the number of messages.

14)   Destination property overflowpolicy means :  Queues can specify overFlowPolicy property to change the effect of exceeding queue limits (either maxbytes or maxmsgs)

when overflowpolicy=discardOld, exceeding queue limits causes the server to discard the oldest message.

if not set the server refuses new messages for the queue.

15)   Destination property global means: Messages destined for a queue or topic with the global property set are routed to the servers that are participating in routing with this server.

16)   Destination property sender_name means:

The sender_name property specifies that the server may include the sender’s username for messages sent to this destination. When this property is enabled, the server takes the user name supplied by the message producer when the connection is established and places that user name into the JMS_TIBCO_SENDER property in the message.

17)   Destination property sender_name_enforced means :

The sender_name_enforced property specifies that messages sent to this destination must include the sender’s user name. The server retrieves the user name of the message producer using the same procedure described in the sender_name property above. However, unlike, the sender_name property, there is no way for message producers to override this property.

18)   Destination property flowControl means : The flowcontrol property specifies the target maximum size the server can use to store pending messages for a destination. This is useful when message producers sent messages much more quickly than message consumers can consume.

Flow control must be enabled for the server before the value in this property is enforced by the server.

19)   Destination property trace means : Specifies that tracing should be enabled for this destination.
The property can be specified as either trace or trace=body.

20)   Destination property import means : The import property allows messages published by an external system to be received by the TIBCO EMS destination, as long as the transport to the external system is configured.

21)   Destination property export means : The export property allows messages published by a client to a topic to be exported to an external system with configured transports.

22)   Destination Property maxRedelivery means : Specifies the number of attempts the server should make to redeliver a message sent to a queue.

The value of this parameter can be set to an integer between 2 and 255. Once the server has attempted to deliver the message the specified number of times, the message is either destroyed or it is placed on the undelivered queue, if the JMS_TIBCO_PRESERVE_UNDELIVERED property on the message is set to true.

23)   Destination property exclusive means: The property is available only for queues. When exclusive is enabled, server sends all the messages (on that queue) to only one customer.

24)   Destination property non-exclusive queues & Round-Robin Delivery: With non-exclusive queues (exclusive set to false) the server distributes messages in a round-robin—one to each receiver that is ready.

25)   Destination property Prefetch means: To reduce waiting time for client programs, the MessageConsumer can prefetch messages—that is, fetch a batch of messages from the server, and hold them for client code to accept, one by one

The MessageConsumer and the server cooperate to regulate fetching according to the queue’s prefetch property.

Table 5 Prefetch 

Value

Description

2 or more The MessageConsumer automatically fetches messages from the server. The MessageConsumer never stores more than this maximum number of messages.
1 The MessageConsumer automatically fetches messages from the server—initiating fetch only when it does not currently hold a message.
none Disables automatic fetch. That is, the MessageConsumer initiates fetch only when the client calls receive—either an explicit synchronous call, or an implicit call (in an asynchronous receiver).
0 The queue inherits the prefetch value. If it has no parent, or no queue in the parent chain sets a value for prefetch, then the default value is 5.When a queue does not set any value for prefetch, then the default value is 0 (that is, inherit the prefetch value).

26) Destination property Expiration means: The server’s expiration property overrides expiration values set by message producers (in client programs). You can set this property for any queue and any topic.

If this property is set for a destination, then when the server delivers a message to that destination, the server replaces the producer’s expiration value with this value.

Specify this value as an integer with units. Legal units are msec, sec, min, hour and day (for example, expiration=10min). When units are absent, the default unit is seconds.

27)   Static queues and topics are assigned certain properties in the configuration file. These static queues and topics become the parents of the dynamic queues and topics, which inherit properties from the elements.

28)   Wildcard “*” means nay token can be in the place of *

For example: foo.* matches all two-part destination names beginning with foo. including foo.bar and foo.boo, but not foo.bar.boo.

29)   Wildcard “>” matches one or more trailing elements.

for example foo.>, matches foo.bar and foo.bar.boo.

30)     The flow_control parameter in tibemsd.conf enables and disables flow control globally for the TIBCO Enterprise Message Service server. When flow_control is disabled (the default setting), the server does not enforce any flow control on destinations. When flow_control is enabled, the server enforces any flow control settings specified for each destination.

31)   JMS supports 2 message delivery modes, persistent and non-persistent modes. This mode is set by the message sender or publisher in the JMSDeliveryMode message header field. Non-Persistent messages are never written to persistent storage. Persistent messages are logged to persistent storage when they are sent.

32) TIBCO Enterprise Message Service (release 4 and later) can exchange messages with TIBCO Rendezvous (release 6.9 and later).

Scope

  • EMS can import and export messages to an external system through an EMS topic.
  • EMS can import messages from an external system to an EMS queue (but queues cannot export).

Figure 13 Rendezvous Transports in the EMS Server

33) The parameter tibrv_transports (in the configuration file tibemsd.conf) globally enables or disables message exchange with Rendezvous. The default value is disabled. To use these transports, you must explicitly set this parameter to enabled.

34) Transport definitions (in the configuration file transports.conf) specify the communication protocol between EMS and the external system; for details, see Configuring Transports for Rendezvous.

35)   timemsd connects to Rendezvous daemons in the same way as any other Rendezvous client would. Transport definitions (in the file transports.conf) configure the behavior of these connections. You must properly configure these transports.

36) Topics can both export and import messages. Accordingly, you can configure topic definitions (in the configuration file topics.conf) with import and export properties that specify one or more external transports:

37)   Queues can import messages, but cannot export them.

38)   The EMS server reads configuration files only once, when the server starts. It ignores subsequent changes to the configuration files.

39)   You can also change the server configuration with administrative requests, using either tibemsadmin (a command line tool).

40) When the server validates and accepts an administrative request, it writes the change to the appropriate configuration file as well (overwriting any manual changes to that file). This policy keeps configuration files current in case the server restarts (for example, in a fault-tolerant situation, or after a hardware failure).

41)

The JMSDeliveryMode message header field defines the delivery mode for the message. JMS supports PERSISTENT and NON_PERSISTENT delivery modes for both topic and queue. EMS extends these delivery modes to include a RELIABLE_DELIVERY mode.

You can set the default delivery mode for the Message Producer, as described in Configuring a Message Producer. This default delivery mode can be overridden by the client when sending a message, as described in Sending Messages.

PERSISTENT

As shown in Figure 4, when a producer sends a PERSISTENT message, the producer must wait for the server to reply with a confirmation. The message is persisted on disk by the server. This delivery mode ensures delivery of messages to the destination on the server in almost all circumstances. However, the cost is that this delivery mode incurs two-way network traffic for each message or committed transaction of a group of messages.

Figure 4 Persistent Message Delivery

NON_PERSISTENT

Sending a NON_PERSISTENT message omits the overhead of persisting the message on disk to improve performance.

If authorization is disabled on the server, the server does not send a confirmation to the message producer.

If authorization is enabled on the server, the default condition is for the producer to wait for the server to reply with a confirmation in the same manner as when using PERSISTENT mode.

Regardless of whether authorization is enabled or disabled, you can use the npsend_check_mode parameter in the tibemsd.conf file to specify the conditions under which the server is to send confirmation of NON_PERSISTENT messages to the producer. See the description for the npsend_check_mode parameter on on page 169 for details.

Figure 5 Non-Persistent Message Delivery

RELIABLE_DELIVERY

EMS extends the JMS delivery modes to include reliable delivery. Sending a RELIABLE_DELIVERY message omits the server confirmation to improve performance regardless of the authorization setting.

Figure 6 Reliable Message Delivery

When using RELIABLE_DELIVERY mode, the server never sends the producer a receipt confirmation or access denial and the producer does not wait for it. Reliable mode decreases the volume of message traffic, allowing higher message rates, which is useful for messages containing time-dependent data, such as stock price quotations.

When you use the reliable delivery mode, the client application does not receive any response from the server. Therefore, all publish calls will always succeed (not throw an exception) unless the connection to the server has been terminated.

In some cases a message published in reliable mode may be disqualified and not handled by the server because the destination is not valid or access has been denied. In this case, the message is not sent to any message consumer. However, unless the connection to the server has been terminated, the publishing application will not receive any exceptions, despite the fact that no consumer received the message.

42)   NON_PERSISTENT and RELIABLE_DELIVERY messages are never written to persistent storage. PERSISTENT messages are written to persistent storage when they are received by the EMS server.

43)    

Persistent Messages Sent to Queues

Persistent messages sent to a queue are always written to disk. Should the server fail before sending persistent messages to subscribers, the server can be restarted and the persistent messages will be sent to the subscribers when they reconnect to the server.

Figure 7 Persistent Messages Sent to a Queue

44) Persistent Messages Published to Topics

Persistent messages published to a topic are written to disk only if that topic has at least one durable subscriber or one subscriber with a fault-tolerant connection to the EMS server. In the absence of a durable subscriber or subscriber with a fault-tolerant connection, there are no subscribers that need messages resent in the event of a server failure. In this case, the server does not needlessly save persistent messages. This improves performance by eliminating the unnecessary disk I/O to persist the messages.

Figure 8 Persistent Messages Published to a Topic

45)   You can set the failsafe property on a topic or queue to specify that persistent messages for the topic or queue be synchronously written to disk. When failsafe is set, the producer remains blocked until the server has completed the write-to-disk operation.

46)    

Message Acknowledgement


The interface specification for JMS requires that message delivery be guaranteed under many, but not all, circumstances. Figure 12 illustrates the basic structure of message delivery and acknowledgement.

Figure 12 Message Delivery and Acknowledgement

The following describes the steps in message delivery and acknowledgement:

  1. A message is sent from the message producer to the machine on which the EMS server resides.
  1. For persistent messages, the EMS server sends a confirmation to the procedure that the message was received.
  1. The server sends the message to the consumer.
  1. The consumer sends an acknowledgement to the server that the message was received. A session can be configured with a specific acknowledge mode that specifies how the consumer-to-server acknowledgement is handled. These acknowledge modes are described below.
  1. In many cases, the server then sends a confirmation of the acknowledgement to the consumer.

The JMS specification defines three levels of acknowledgement for non-transacted sessions:

  • CLIENT_ACKNOWLEDGE specifies that the consumer is to acknowledge all messages that have been delivered so far by the session. When using this mode, it is possible for a consumer to fall behind in its message processing and build up a large number of unacknowledged messages.
  • AUTO_ACKNOWLEDGE specifies that the session is to automatically acknowledge consumer receipt of messages when message processing has finished.
  • DUPS_OK_ACKNOWLEDGE specifies that the session is to “lazily” acknowledge the delivery of messages to the consumer. “Lazy” means that the consumer can delay acknowledgement of messages to the server until a convenient time; meanwhile the server might redeliver messages. This mode reduces session overhead. However, should JMS fail, the consumer may receive duplicate messages.

EMS extends the JMS acknowledge modes to include:

The acknowledgement mode is set when creating a Session, as described in Creating a Session.

NO_ACKNOWLEDGE

NO_ACKNOWLEDGE mode suppresses the acknowledgement of received messages. After the server sends a message to the client, all information regarding that message for that consumer is eliminated from the server. Therefore, there is no need for the client application to send an acknowledgement to the server about the received message. Not sending acknowledgements decreases the message traffic and saves time for the receiver, therefore allowing better utilization of system resources.

Sessions created in no-acknowledge receipt mode cannot be used to create durable subscribers.

Also, queue receivers on a queue that is routed from another server are not permitted to specify NO_ACKNOWLEDGE mode.

EXPLICIT_CLIENT_ACKNOWLEDGE

EXPLICIT_CLIENT_ACKNOWLEDGE is like CLIENT_ACKNOWLEDGE except it acknowledges only the individual message, rather than all messages received so far on the session.

One example of when EXPLICIT_CLIENT_ACKNOWLEDGE would be used is when receiving messages and putting the information in a database. If the database insert operation is slow, you may want to use multiple application threads all doing simultaneous inserts. As each thread finishes its insert, it can use EXPLICIT_CLIENT_ACKNOWLEDGE to acknowledge only the message that it is currently working on.

EXPLICIT_CLIENT_DUPS_OK_ACKNOWLEDGE

EXPLICIT_CLIENT_DUPS_OK_ACKNOWLEDGE is like DUPS_OK_ACKNOWLEDGE except it ’lazily” acknowledges only the individual message, rather than all messages received so far on the session.

47)   The EMS APIs allow for both synchronous or asynchronous message consumption. For synchronous consumption, the message consumer explicitly invokes a receive call on the topic or queue. When synchronously receiving messages, the consumer remains blocked until a message arrives. See Receiving Messages for details.

48)   The consumer can receive messages asynchronously by registering a message listener to receive the messages. When a message arrives at the destination, the message listener delivers the message to the message consumer. The message consumer is free to do other operations between messages.

49)   When authorization is enabled, the server requires a name and password before users can connect. Only authenticated users can connect to the server. The form of authentication can be either an X.509 certificate or a username and password (or both).

50)   Even when authorization is enabled, the administrator (admin) may explicitly allow anonymous user connections, which do not require password authorization. To allow these connections, create a user with the name anonymous and no password.

51) For communication security between servers and clients, and between servers and other servers, you must explicitly configure SSL within EMS; see Using the SSL Protocol.

SSL communication requires software to implement SSL on both server and client. The EMS server includes the OpenSSL implementation. Java client programs must use either JSSE (part of the Java environment) or separately purchased SSL software from Entrust; neither of these are part of the EMS product. C client programs can use the OpenSSL library shipped with EMS.

52)autocommit [on|off]

When autocommit is set to on, the changes made to the configuration files are automatically saved to disk after each command. When autocommit is set to off, you must manually use

the commit command to save configuration changes to the disk.

By default, autocommit is set to on when interactively issuing commands.

Entering autocommit without parameters displays the current setting of autocommit (on or off)

53)

compact

compact store_type [max_time]

Compacts the database store files.

  • To compact the asynchronous file, specify either a, async, or asynchronous.
  • To compact the synchronous file, specify either s, sync, or synchronous.

Since compaction can be a lengthy operation, and it blocks other database operations, you may specify a time limit (in seconds). Zero is a special value, which specifies no time limit. When the time limit is absent, the default is zero, and the administration tool asks for confirmation.

We recommend compacting the database store files only when the database Used Space usage is 30% or less (see show db ).

54)    

create rvcmlistener

create rvcmlistener [transportName] name subject

Registers an RVCM listener with the server so that any messages forwarded through a tibrvcm transport (including the first message sent) are guaranteed for the specified listener. This causes the server to perform the TIBCO Rendezvous call tibrvcmTransport_AddListener.

The parameters are:

  • transportName — the name of the transport to which this RVCM listener applies. Note that the square brackets [ ] DO NOT indicate that the transport name is an option; they must be included around the name.
  • name — the name of the RVCM listener to which topic messages are to be exported.
  • subject — the RVCM subject name that messages are published to. This should be the same name as the topic names that specify the export property.

For more information, see tibrvcm.conf and Rendezvous Certified Messaging (RVCM) Parameters.

55)
rotatelog

rotatelog

Force the current log file to be backed up and truncated. The server starts writing entries to the newly empty log file.

The backup file name is the same as the current log file name with a sequence number appended to the filename. The server queries the current log file directory and determines what the highest sequence number is, then chooses the next highest sequence number for the new backup name. For example, if the log file name is tibems.log and there is already a tibems.log.1 and tibems.log.2, the server names the next backup tibems.log.3.

56)   Example commands : show db, show config, show bridges, show server, show stat, whoami

The following tables summarize the parameters in tibemsd.conf according to category. The sections that follow provide more detail on each parameter.

Table 24 Global System Parameters

Parameter Name

Description

See Page

authorization Enable or disable server authorization. 167
flow_control Enable or disable flow control for destinations. 167
listen Specifies the port on which the server is to listen for connections from clients. 168
npsend_check_mode Specifies when the server is to provide confirmation upon receiving a NON_PERSISTENT message from a producer. 169
password Password used to authenticate with other routed servers that have authorization enabled. 170
routing Enable or disable routing functionality for this server. 170
server Name of server. 170
startup_abort_list Specifies conditions under which the server is to exit during its initialization sequence. 170
user_auth Specifies the source of authentication information used to authenticate users attempting to access the EMS server. 172

Table 25 Storage File Parameters

Parameter Name

Description

See Page

store Specifies the directory in which the server stores data. 173
store_crc Specifies whether the EMS server validates CRC checksum data when reading the store files. 173
store_minimum Specifies the amount of disk space to preallocate for EMS store files. 173
store_truncate Specifies whether the EMS server is to periodically truncate the storage files to relinquish unused disk space. 173

Table 26 Connection and Memory Parameters

Parameter Name

Description

See Page

max_connections Specifies the maximum number of simultaneous client connections to the server. 174
max_msg_memory Specifies the maximum memory the server can use for messages. 174
msg_swapping Enable or disable message swapping. 174
reserve_memory Specifies the amount of memory to reserve for use in emergency situations. 175
msg_pool_block_size
msg_pool_size
Specifies the size of the pool to be pre-allocated by the server to store messages. 175

Table 27 Detecting Network Connection Failure Parameters

57)   The logfile configuration parameter in tibemsd.conf controls the location and the name of the log file. The logfile_max_size configuration parameter allows you to specify the maximum size of the current log file. Set the parameter to 0 to specify no limit. Use KB, MB, or GB units.

Once the log file reaches its maximum size, it is copied to a file with the same name as the current log file except a sequence number is appended to the name of the backup file. The server queries the directory and determines the first available sequence number. For example, if the current log file is named tibems.log, the first copy is named tibems.log.1, the second is named tibems.log.2, and so on. You can move the files out of the log directory, if desired, and the next log file is determined based on the first available numbered backup in the log file directory.

You can also dynamically force the log file to be backed up and truncated using the rotatelog command in tibemsadmin. See Command Listing for more information about the rotatelog command.

58)

Tracing on the server: Trace messages can be sent to a log file, the console, or both. You configure tracing in the following ways:

  • By configuring the log_trace and/or console_trace parameters in the tibemsd.conf file; see Table 12.
  • By specifying the -trace option when starting the server
  • By using the set server command when the server is running.

log_trace and console_trace can be used to configure what types of messages are to go to the log file and to the console.

Examples

The following example sets the trace log to only show messages about access control violations.

log_trace=ACL

The next example sets the trace log to show all default trace messages, in addition to SSL messages, but ADMIN messages are not shown.

log_trace=DEFAULT,-ADMIN,+SSL

The next example sends a trace message to the console when a TIBCO Rendezvous advisory message arrives.

console_trace=RVADV

59)

System Monitor Topics

The TIBCO Enterprise Message Service server can publish topic messages for several system events. For example, the server can publish a message when users connect or disconnect.

The TIBCO Enterprise Message Service server can publish messages to various topics when certain events occur. There are several types of event classes, each class groups a set of related events. For example, some event classes are connection, admin, and route. Each event class is further subdivided into the events for each class. For example, the connection class has two events: connect and disconnect. These event classes are used to group the system events into meaningful categories.

All system event topic names begin with $sys.monitor. The remainder of the name is the event class followed by the event. For example, the server publishes a message to the topic $sys.monitor.connection.disconnect whenever a client disconnects from the server. The naming scheme for system event topics allows you to create wildcard subscriptions for all events of a certain class. For example, to receive messages whenever clients connect or disconnect, you would create a topic subscriber for the topic $sys.monitor.connection.*.

Monitor topics are created and maintained by the server. Monitor topics are not listed in the topics.conf file. Users can subscribe to monitor topics but cannot create them.

60)   The TIBCO Enterprise Message Service server tracks the number of incoming or outgoing messages, but only messages sent or received by a producer, consumer, or route are tracked. The server also sends system messages, but these are not included in the number of messages.

61)   You can view overall server statistics by executing the show server command. The server_rate_interval configuration parameter controls the collection interval for server statistics. The parameter can be set in the configuration file or dynamically using the set server command. This parameter can only be set to positive integers greater than zero

62)   Each producer, consumer, destination, and route can gather overall statistics and statistics for each of its destinations. To enable statistic gathering, you must set the statistics parameter to enabled. This parameter can be specified in the configuration file, and it can be changed dynamically using the set server command

To enable detailed statistics, set the detailed_statistics parameter to the type of statistics you wish to receive. The parameter can have the following values:

  • NONE — disables detailed statistic gathering.
  • CONSUMERS — enables detailed statistics for topic subscribers with wildcard topic names.
  • PRODUCERS — enables detailed statistics for producers that do not specify a destination when they are created.
  • ROUTES — enables detailed statistics for routes

63)   When statistic collecting is enabled, you can view statistics for producers, consumers, routes, and destinations using the show stat command in the administration tool.

Fault Tolerance Overview


You can arrange TIBCO Enterprise Message Service servers for fault-tolerant operation by configuring a pair of servers—one primary and one backup. The primary server accepts client connections, and interacts with clients to deliver messages. If the primary server fails, the backup server resumes operation in its place. (We do not support more than two servers in a fault-tolerant configuration.)

Shared State

A pair of fault-tolerant servers must have access to shared state, which consists of information about client connections and persistent messages. This information enables the backup server to properly assume responsibility for those connections and messages.

Figure 21 illustrates a fault-tolerant configuration of TIBCO Enterprise Message Service.

Figure 21 Primary Server and Backup Server

Locking

To prevent the backup server from assuming the role of the primary server, the primary server locks the shared state during normal operation. If the primary server fails, the lock is released, and the backup server can obtain the lock.

Configuration Files

When a primary server fails, its backup server assumes the status of the primary server and resumes operation. Before becoming the new primary server, the backup server re-reads all of its configuration files. If the two servers share configuration files, then administrative changes to the old primary carry over to the new primary.

Posted in Tibco

Java Hello world

class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!"); // Display the string.
    }
}
Tagged with:
Posted in Java
Design a site like this with WordPress.com
Get started