Wednesday, 19 August 2015

Horizontal and Vertical Clustering


There are two methods of clustering
  • Horizontal Clustering
  • Vertical Clustering

Horizontal Clustering:
Horizontal scaling involves running multiple Java application servers (JVM) on two or more separate physical hardware’s (machines). When you scale horizontally, you add additional hardware that hosts additional JVM to the cluster.

Vertical Clustering:

Vertical scaling involves multiple Java application servers (JVM) running on a single physical machine. When you scale vertically, you join additional JVM to the cluster by adding to the same physical machine, which is limited by the limitation of the same physical machine.

Saturday, 15 August 2015

Disabling and Enabling Admin Console


Disabling and Enabling Admin Console

Many at times for most of our administration work including the changes (deployments, start/stop of servers, etc) or configurations (JMS, creation/deletion/editing of our servers, etc) we use our weblogic admin console.
But, for security reasons some of the banking companies for its core banking applications prefer to disable the admin console in its banking applications.
This short and sweet article mainly targets to present you on how to enable and disable your admin console:
Disabling your Admin Console:
We can disable our weblogic admin console in two different ways
1)      Admin console
2)      Weblogic Scripting Tool
From Admin console:-
To disable access to the Administration Console:
  1. After you log in to admin console click Lock & Edit.
  2. In the left pane of the Console, under Domain Structure, select the domain name.
  3. Select Configuration > General, and click Advanced at the bottom of the page.
  4. Deselect Console Enabled.
  5. Click Save.
  6. To activate these changes, click Activate Changes.
From WLST:-
connect(“weblogic“,”weblogic“,”t3://localhost:7001“)
edit()
startEdit()
cmo.setConsoleEnabled(false)
save()
activate()
disconnect()
exit()
Enabling the Admin Console:
After we disable the admin console we can enable it again by using WLST.
Following are the steps on the same:
connect(“weblogic“,”weblogic“,”t3://localhost:7001“)
edit()
startEdit()
cmo.setConsoleEnabled(true)
save()
activate()
disconnect()
exit()
Note: Here,
1)      weblogic and weblogic are the user id and password of admin console.
2)      t3://localhost:7001 is the admin console URL

3)      After we enable/disable the admin console RESTART your admin server

Shell Programs

Shell Sample Programs


1. WAS,to display list of files, the current working user‘s list and present working directory
$vi sp1
ls -x
who
pwd


:wq(save and quit)
Execution of shell program:
Sh is the command to execute bourn shell programs

eg: $sh sp1
or
$chmod 744 sp1

$./sp1

2)WAS, to display address

$vi sp2

echo “Multics Scripting Institute”
echo “No:109, 1st floor”
echo “Eurekha court,”
echo “4th floor”
echo “Ameerpet,”
echo “Hyderabad”

:wq(save and quit)

3)WAS, to  count no of users are currently logged into the system

$vi sp3.sh

echo “There are `who |  wc  -l ` users”

:wq(save and quit)

4)WAS, to read name and display

$vi  sp4.sh

echo “what is your name?”
read name
echo “hello $name”

:wq(save and quit)

Note :- read is command to read variable form the user .Read command reads value form keyboard up to space or enter key.
Eg1: read a
Eg 2: read a b--c

5)WAS, to read 2 number and display

Vi sp5

echo “enter 2 numb:\c”
read a b
echo “your numbers are $a and $b

:wq(save and quit)

OPERATORS:

1 .Arithmetic operators
2. Relational operators
             a. Numeric comparison operators
             b. String comparison operators
3. Logical operators


1. Arithmetic Operators
Operator                                                             Meaning
+                                                                             Sum
-                                                                       Difference
*                                                                             Product
/                                                                              Division
%                                                                            Modulus division

2. Numeric comparison operator
Operator                                                             Meaning
-gt                                                                          greater than
-ge                                                                         greater than equal to
-lt                                                                            less than
-le                                                                           less than or equal to
-eq                                                                         equal to
-ne                                                                         not equal to

3. String Comparison Operators
Operator                                                             Meaning
 >                                                                            Greater than
<                                                                             Less than
=                                                                             Equal to
!=                                                                            Not equal to

4.Logical Operators
Operator                                                             Meaning
-a                                                                            Logical AND
-o                                                                            Logical OR
!                                                                              logical NOT

5.Assignment operator                                 =

In UNIX for each and every operator, note that there should be space before and after operators.
If we don’t give space for “=” operator it can be consider as assignment else string comparison operator

6)WAS, to read 2 float numbers and display sum, difference, product and division

$vi sp7
echo “enter 2 float numbers” read a b
c=`echo $a + $b I bc`
 echo “a+b=$c”

7)WAS, to read 2 numbers an d display sum, difference, product and division

visp6

echo “enter 2 numbers”
read a b
c=`expr $a + Sb`
echo “a+b$c”
c=`expr $a - $b`
echo “a-b=$c”
c=`expr $a \* $b`
echo “a*b=$a”
c=`expr $a / $b`
echo “alb=$c”

:wq(save and quit)

Note: expr is the command to evaluating arithmetic expressions. But expr is capable of carring out only integer arithmetic.

....WAS, to read 2 float number and display Sum, difference, product and division

$vi sp7

echo “enter 2 float numbers”
read a b
c=`echo $a+$b | bc`
echo”a+b=$c”
c=`echo.$a - $b | bc`
echo “a-b=$c”
c=`echo $a \* $b bc`
echo “a*b=$a”
c=`echo $a / $b | bc`
echo “alb=$c”

:wq(save and quit)


CONTROL STATEMENTS:

There are four types of control instructions in shell. They-are:

1. Sequence Control Instruction
2. Selection or Decision Control Instructions
3. Repetition or Loop Control Instruction
4. Case Control Instruction

The sequence control instruction ensures that the instructions are executed in the same order in which they appear in the program. Decision and case control instructions allows the computer to take a decision as to which instruction is to be executed next. The loop control instruction helps computer to executer group of statements repeatedly.

Decision Control Statement
1. if —then-fl statement
2. if-then-else-if statement
3. if-then-elif-fi statement
4. case-esac statement

1.if-then-fi statement
Syntax:
if control command
…………..
…………
…………..

fi
The if statement of UNIX is concerned with the the exit status of a command. The exit status indicates whether the command was executed successfully or not. The exit status of a command is 0 if it has been executed successfully, 1 otherwise.

8) WAS, to change directory

$vi sp8

echo enter directory name
read  dname
if  cd  $dname
then
echo “changed to $dnarne”
pwd
fi

:wq(save and quit)

2.Jf-then-else-fi Statement
syntax
if condition
then
………
………
else
………
………

fi
The exit status of the control command is 0 then it executes then statement otherwise it executes else statements.


9) WAS, to copy a file

$vi sp9
echo enter source filename and target file and name
read  src  trg
if  cp  $src  $trg
then
echo   file copied successfully
else
echo   failed to copy the file
fi

:wq(save and quit)

10) WAS,  to search string in a file

$vi sp10.sh

echo “enter a file name”
read  fname
echo “enter to string to search”
read str
if  grep $str  $fname
then
echo “$str is found in the file $file”
else
echo “$str is not found in $fname”
fi

:wq(save and quit)

11)WAS, to find greatest number of 2 numbers

vi sp 11
echo enter two numbers
read a b
if  [ $a –gt  $b ]
then
echo $a is the greatest value
else
echo $b is the greatest value

fi

:wq(save and quit)

12) WAS, to check given no is even or odd

$vi sp12

echo enter a number
read n
if [  `expr $n % 2`  -eq  0 ]
then
echo $n is even number
else
echo $n is odd number
fi

:wq(save and quit)

The Test Command

If constructs depends upon whether or not the condition results into true or not.
If constructs are generally used in conjunction with the test command. The test command helps us to find the contents of a variable, the number of variables and the type of file or kind of file permission. The test command returns an exit status after evaluating the condition.

Syntax: -
If test condition
Then
Commands
Else
Commands
fi

13) WAS, to check how many users working on the system

$vi  sp13

total=`who | wc –l`
if  [  $total  -eq  1 ]
then
echo “you are the only user working…
else
echo “there are $total user working…
fi

:wq(save and quit)

14)  WAS,  to check given number is +ve or –ve number

$vi sp14

echo “enter a number”
read num
if  test  $nurn  -gt  0
then
echo “$num is +ve number” else
echo “$num is —ve number”
fi

;wq(save and quit)

15)  WAS, to find student result

4vispl5

echo “enter three subject marks:”
read ml m2 m3
if  [  $ml  -ge  40  ]
then
if  [  $m3 -gt  40 ]
then
if  [  $m3  –gt  40  ]
then
echo “PASS”
else
echo “FAIL”
fi
else
echo “FAIL”
fi
else
echo “FAIL’
fi
:wq(save and qut)

16)WAS, to print greeting

$vi spl6

hour=`date | cut  -c 12,33`

if   [  $hour  —ge   0  —a   $hour  —le   11]
then
echo “Good Morning”
else

if  [  $hour  -ge  12  -a  $hour -Ie 17  ]
then
echo “Good Afternoon”
else
echo “Good Evening”
fi
fi

:wq(save and quit)

File Test Commands
The test command has several options for checking the status of a file.
-e            True if the file exist.
 -s           True if the file exists and has a size greater  than 0
-f             True if the file exists and is not directory
-d            True if the file exists and is a directory file
-c            True if the file exists and character special file
-b            True if the file exists is a block special file
-r             True if the file exists and have a read permission to it
-x            True if the file exists and have a execute permission to it
-w           True if the file exists and have a write permission to it


17) WAS, to  check for ordinary file and display it contents
$vi sp17

echo enter a file name
read fname
if test  -f  $fname
then
cat  $fname
else
echo “given file is not ordinary file”

:wq(save and quit)

18) WAS, to  check give file is ordinary or directory file

$vi sp18

echo “enter a file name:”
read fnarne
if  [ -f  $fname ]
then
cat  $fname
elif  [  -d  $fname   ]
then
ls
else
echo $fname is not file and not a directory
fi

:wq(save and quit)

19) WAS, to check read permission

$vi sp19

echo “enter a file name
read  fname
if  [  -r  $fname  ]
then
cat  $fname
else
chmod  u+r  $fname
cat  $fname
fi

:wq(save and quit)

20) WAS, to append data to the file

$vi sp20

echo “enter a filename”
read  $fname
if  [  -f  $fname  ]
then
if [  -w   $fname  ]
then
echo “enter data to file to stop press ctrl+d...”
cat  >>$fnarne
else
chmod  u+w   $fname
echo “enter data to file to stop press ctrl+d…”
cat  >>$fname
fi
else
echo “enter data to file to stop press ctrl+d…”
cat  >>$fname

fi
:wq(save and quit)

String Test Commands

Condition                            Meaning
String 1 = string2               True if the strings are same
Stringi != string2               True if the strings are different
-n string 1                            True if the length of string is greater than 0
-z string                                True if the length of the string is zero

21) WAS, to compare two strings

$vi  sp21.sh

echo “enter first string:”
read str1
echo “enter second string:”
read str2
if test $str1  =  $str2
then
echo “both strings are equal”
else
echo “strings are not equal”
fi

:wq(save and quit)

22) WAS, to check given string is empty or not

$vi sp22

echo enter a string
read str
if  [  -z  $str  ]
then
echo “string is empty”
else
echo ‘given string is not empty”
fi

:wq(save and quit)


Case Control Statement

Syntax -
Case value in
Choicel)
…………..
…………..
‘’
‘’

cho ice2)
………
………
‘’
‘’
choice3)
………
………
‘’
‘’
esac

Firstly, the expression following the case keyword is evaluated. The value that it yields is then matched, one by one against the potential choices (choice1, choice2 and choice3 in the above form). When a match is found, the shell executes all commands in that case up to;;. This pair of semicolons placed at the end of each choice is necessary.

23)Sarnple program for case

$vi sp23

echo “enter a number between 1 to 4”\c”
read num
case $nurn in
1)echo “you entered 1” ;;

2)echo “you entered 2” ;;

3)echo “you entered 3” ;;

4)echo “you entered 4” ;;

*)echo “invalid number, enter number between 1to4 only” ;;

esac

:wq(save and quit)

24) WAS, to check given character is upper case alphabet or lower case alphabet or digit or special character

$vi sp24

echo “enter a single character”
read ch
case  $ch  in
[a-z])echo   “you entered a small case alphabet” ;;

[A-Z])echo   “you entered a upper case alphabet” ;;

[0-9])echo  “you entered a digit” ;;

?)echo  “you entered a special character”;;


*)echo “you entered more than one character”;;

esac
:wq(save and quit)

25)WAS, to display file conten ts or write on to file or execute based on user choice

$vi sp25

echo “enter a file name:\c”
read   fname
echo            “Main Menu”
echo  “======================”
echo  “r. read mode”
echo  “w.write mode”
echo   “x. execute mode”
echo   “enter mode:\c”
read  mode
case  $mode  in
r)
if  [ -f $fname  -a   -r  $fname  ]
then
cat  $fname
fi
;;
w)
if  [ -f  $fname   -a   -w  $fname  ]
then
echo “enter data to file at end press ctrl+d:”
cat   >$fname
fi
;;
x)
if  [  -f  $fname   -a  -x  $fname  ]
then
chmod  u+x  $fname
$fname
fi
;;
*)echo  ”you entered invalid mode…”
;;

esac


:wq(save and quit)

Looping Control Statements
A loop involves repeating some portion of the program either a specified no of times of times or until a particular condition is being satisfied. There are three methods by way of which we can repeat a part of a program. There are

1) Using a while statement
2) Using a until statement’
3) Using a for statement


While Statement
Syntax

while [condition j
do
……………
……………
……………
done

The statements within the while loop would keep on getting executed till the condition is true. When the condition is false, the control transfers to after done statement.

27) WAS, to display numbers 1 to 10

$visp27

echo “the number form 1 to 10 are:”
i=1
while  [  $i  -Ie  10 ]
do
echo  $i
i=`expr  $i  +  1`
done

:wq(save and quit)


28) WAS, to copy file from root to user directory

$vi sp28

flag=1
while  [  $flag   -eq   1  ]
do
echo “enter a filename”
read  fname
cp  $fname    /usr/sv/$fname
echo “$fname copied………..”
echo “do u wish to continue [1 -yes/0-no]:  ”
read flag
done


:wq(save and quit)

The Break Statement
When the keyword break is encountered inside any loop, control automatically passes to the first statement after the loop.
The Continue Statement
When the keyword continues is encountered inside any loop, control automatically passes to the beginning of the loop.
29)WAS, to display file contents if file existing

$vi sp29
x0
while  test  $x=0
do
echo “enter a file name:\c”
read  fname
if   test  ! –f  $fname
then
echo “$fname is not found………..”
continue
else
break
fi
done
cat $fnarne | more

:wq(save and quit)

The Until Loop
Syntax
until [condition j
do
……………
……………
……………
done

The statements within the until loop keep on getting executed till the condition is false. When the condition is true the control transfers to after done statement.

30) WAS, to print numbers 1 to 10

$vi sp3O

i=1
until  [  $i  -gt  10  ]
do
echo  $i
i=`expr$i+1`
done

:wq(save and quit)

The True and False Command
To execute the loop an infinite no of times.

31) Write sample program for true command

$vi sp3l

while true
do
clear
banner “hello”
sleep 1
clear
banner “Tecnosoft”
sleep 1
done

:wq(save and quit)

Note: The above program executes continuous to stop execution press ctrl + break

32) Write sample program for false command

$vi sp32

until  false
do
clear
banner “hello”
sleep 1
clear
banner “Tecnosoft”
sleep 1
done

:wq(save and quit)
The Sleep Command
The sleep command stops the execution of the program the specified no of seconds.

The For Loop
Syntax

For variable in va1ue1value2 value3 . ... . value
do
………………….
……………….
done
The for allows us to specify a list of values which the variable in the loop can take. The loop is then executed for each value mentioned in the list.

33) WAS, to demonstrate for loop

$vi sp33

for i in 1 2 3 4 5
do
echo $i
done

:wq(save and quit)

34) WAS, to demonstrate for loop

$vi sp34

for  i  in Multics is a training institute.
do
echo $i
done

:wq

35) WAS,to display all files in current directory

$vi sp35

for  i in *
do
if  test   -f  $i   -a   -r  $i
then
cat $i |more
sleep 1
clear
fi
done

:wq(save and quit)

36)WAS, to display all sub-directories in the current directory

$vi sp36

for I in*
do
if [  -d  $i  ]
then
echo $i
fi
done

:wq(save and quit)

Positional Parameters
When the arguments are passed with the command line, shell puts each word on the command line into special variables. For this, the shell uses something called as “positional parameters;. These can be thought of as variables defined by the shell, They are nine in number, named $1 through $9.

Consider the following statement, where sp37 is any executable shell script file and the remaining are the arguments
$sp37 Multics is a computer training and development institute

On entering such command, each word is automatically stored serially in the positional parameters. $1 through $9

37) write program to copy a file using positional parameters

vi sp37

if  cp  $1  $2 -
then
echo “file copied successfully”
else
echo “failed to copy”
fi

:wq(save and quit)

$chmod 744 sp37

$sp37 al a2
in above command it passes al to $1 and a2 into $2, then it copies al
contents to a2.

Special Characters
$*, $@                   Contains entire string of arguments

$# -                        Contains the no for argument specified in the command

$?                           Holds the value of exit status of the previous command

$$                           Holds user parent id




shell script

                                       SHELL SCRIPTING

SHELL: -shell is command line interpreter. It takes commands from user and executes them. it is an interface between user and kernel.  The three most widely used UNIX shells are Bourne shell .kom shell and c shell.


Shell
Developed by
Shell
Prompt
Execution
Command
Bash shell
Denis Richie
$
sh
Bourne shell
Steven courne
$
Sh
Korn shell
David korn
$
Ksh
C shell
Bill joy, california university student
%
Csh

      Each shell has merits and demerits of its own. Moreover the shell scripts written for one shell may not work with the other shell. This is because different shells use different shells use different mechanism to execute the commands in the shell script. Bourne shell since it is one of the most widely used UNIX shells in existence today.

      Almost all UNIX implementations offer the Bourne shell as part of their standard configuration. It is smaller than the other two shells and therefore more efficient for most shell processing. However it lacks features offered by the c and korn shell.

      All shell programs written for the Boume shell are likely to work with the korn shell, the reverse however may not be true, this is so since the facilities like arrays, command aliasing and history mechanism available in the korn shell are not supported by the bourne shell.

The c shell programming language resembles the c language and is quite different from the language of the bourne shell, only the very basic shell scripts will run under both the c and bourne shell; a vast majority will not shell keeps track of commands as you enter them (history) and allows you to go back and execute them again without typing the command. Or, if you want to, you can recall them, make modifications, and then execute the new command.

chsh


Shell program:-
     A shell program is nothing but a series of such commands, instead of specifying one job at a time, we give the shell a to -do list —a program — that carries out an entire procedure. such programs are known as “shell scripts”.

When to use shell scripts:

  1. Customizing your work  environments, for example, every time you log in if                                                  you want to see the current date, a welcome message and the list of users who have logged in you can write a shell script for the same.
  2. automating your daily tasks, for example, you a may want to back up all your programs at the end of day, this can be done using a shell script.
  3. Automating repetitive tasks. f xth1e, the repetitive task of compiling a c program, linking it with some libraries and executing the executable code can be a shell script.
  4. Executing important system procedures like shutting down the system, formatting a disk, creating a file system, mounting the file system, letting the user the floppy and finally unmounting the disk.
  5. Performing same operation on many files. Or example, you may want to rep lace a string with a string myprintf in all the c programs present in a directory
Shell Variables:-
           Variable is, a data name and it is used to store value. Variable value can change during execution of the program.

Variables in UNIX are two types.

1. Unix-defined variables or system variables
2. User defined variables

Unix-defined variables:

          These are standard variables which are always accessible the shell provides the values for these variables these variable are usually used by the system itself and govern the environment we work under. If we so desire we can change the values of these variables as per our preferences and customize the system environment.
          The list of all system variables and their values can be displayed by
Saying at the $prompt,
$set
HOME=/usr/sv
HZ=100
IFS=
LOGNAME=sv
MAII=usr/spool/mail/sv
MAILCHECK=600
OPTINd=l
PATH=/bin :Iusr/b in:/usr/sv:/bin:.
PS1=$
SHELL=/bin/sh
TERM=vt100
TZ=IST-5:30

Variable
Meaning
PS1
Primary shell prompt
PS2
The system prompt 2, default value is “>”
PATH
Defines the path which the shell must search in order to execute any command or file
HOME
Stores the de fault working directory of the user
LOGMAN
Stores the login name of  the user
MAIL
Defines the file where the mail of the user is stored
MAILCHECK
Defines the duration after which the shell checks whether the user has received any mail. By default its value is 600(seconds)
IFS
Defines the name of your default working shell
SHELL
Defines the name of your default working shell
TERM
Define the name of the terminal zone in which you are working
TZ
Defines the name of the Zone in which we are working


User Defined Variables
 These are defined by user and are used most extensively in shell programming.

Rules for creating User Defined Shell Variables: -
1.   The first character of a variable name should be alphabet or underscore.
2.   No commas or blanks are allowed within a variable name
3.   Variables names should be of any reasonable length
4.   Variable names are case sensitive, that isName, nAme, name are all different variable names.
5.   Variable name shouldn’t be a reserve word
Shell Keywords:-
Keywords are the Words whose meaning has already been explained to the shell. The keywords are .also called as “Reserve Words”.
The lists of keywords available in Bourne shell are

Echo
if
Read
else
Set
fi
unset
while
Readonly
do
Shift
Done
Export
For

Until
trap
case
wait
esac
eval
break
exec
continue
ulimit
Exit
Umask
return



1.Echo
             echo command is used to display the messages on the screen and is used to display the value stored in a shell variable.

Eg 1: $echo “Multics is a training institute”
            Multics is a training institute

Note: double quotes are option in echo statement.

Eg 2: $echo “today date is:`date`”
            Today date is sat mar 4 o4:40:i0 1ST 2005
Note: the UNIX command should be in back quotes in echo statement
Otherwise it treats, as text.
Eg 3: $echo “my file has we —I file lines
               My file has 10 lines
Eg 4: $echo my log name is:`logname`.
             My logname is Sv
Eg 5: $echo “my present working directory is :`pwd` ”
                My present working directory is :/usr/sv/abc

Shell variables
Eg 1: $a=10
Note: there are no predefined data types in UNIX. Each and every thing it treats as character. Each character occupies 1 byte of memory.

Eg 2:$b2000
In above example a occupies 2 bytes and b occupies 4 bytes of memory
Reading of variable
               $ is the operator to read variable value
Eg 1: $n=l00
          $echo $n
             100
Eg 2: $name=”Multics”
          $echo $name
              Multics
$echo welcome to $name
Welcome to Multics
Eg 3: $now=`date`
          $$now
           sat mar 4 o4:40:10 1ST 2005

Eg 4: $mypath=/usr/sv/abc/a 1 /a2
           $cd $mypath
now it changes to a2 directory, to check say at $ promt pwd command $pwd
/usr/sv/abc/a 1 /a2

Null Variables
 A variable which has been defined but has not been given any value is known as a null variable. A null variable can be created in any of the following ways.

1.$n=””
2.$n=”
3.$n=

$echo n
on echoing a null variable, only a blank line appears on the screen.

Constant:
Constant is a fixed value. It doesn’t change during execution of  the  program
$a=20
$readonly  a

When the variable are made readonly, the shell doe not allow us to change their values, so a value can read but can‘t change.

Note: If we want the shell to forget about a variable altogether, we use the unset command.
$unset  a
on issuing the above command the variable a and with it the value assigned to it are erased from the shell’s memory.