Shell Scripting

Monday, October 12, 2015

How to Set a Static IP in Ubuntu 14.04

By default the Ubuntu 14.04 server sets the interface to use DHCP, here’s how to set a static IP address.

Edit “/etc/network/interfaces”.  In this example set-up we’ll use 192.168.10.207 as our server IP address:

$sudo nano /etc/network/interfaces

To find out an ipadress in Linux
Ifconfig eth0 | grep "inet addr:"
Sample o/p: inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0

How to download youtube videos in Ubuntu

You can install youtube-dl and use it to download YouTube videos.

 sudo apt-get install youtube-dl

 youtube-dl https://www.youtube.com/watch?v=TA1MSeWA6Wk

Install weblogic in 64 bit mode

Use below command to install weblogic in 64 bit mode
 
java -d64 -jar wlsversion_generic.jar -mode=console

Post java install in Linux, installing dependency packages

After extracting downloaded java setup, In the terminal when I type: java -version It comes back with the below errors

krishna@lifebookah531:~/jdk1.7.0_79$ java -version
The program 'java' can be found in the following packages:
 * default-jre
 * gcj-4.8-jre-headless
 * openjdk-7-jre-headless
 * gcj-4.6-jre-headless
 * openjdk-6-jre-headless
Try: sudo apt-get install <selected package>

As per above error, default-jre package was not properly installed. BY using the below command, installed required packages.

command: sudo apt-get install default-jre

















































now able to see java version details

 

Sunday, October 11, 2015

How to install Putty in Ubuntu

Step:1 Issue the below Command to install Putty

# sudo apt-get install putty




















Step 2: Type Putty at prompt and putty window will get opened like below

Friday, May 22, 2015

Script to rotate Weblogic .out files

#!/bin/ksh

#This script will rotate all log files
#that are included in DIRLIST below.

#Read in log file directory list from the control file above
DIRLIST=`cat $home/scripts/log_list.ctrl`

for DIRECTORY in $DIRLIST
do

#Rotate archived access and error log files

#If an archived access or errors file doesn't exist,
#then create it.


if [[ ! -a ${DIRECTORY}.05.gz ]];
  then
    touch ${DIRECTORY}.05.gz
#Puts entry into log file.
        echo "- $(date): The following log file didn't exist and is now created: $DIRECTORY.05.gz" >> $home/output/wlLogRotate.log
fi

if [[ ! -a ${DIRECTORY}.04.gz ]];
  then
    touch ${DIRECTORY}.04.gz
#Puts entry into log file.
        echo "- $(date): The following log file didn't exist and is now created: $DIRECTORY.04.gz" >> $home/output/wlLogRotate.log
fi

if [[ ! -a ${DIRECTORY}.03.gz ]];
  then
    touch ${DIRECTORY}.03.gz
#Puts entry into log file.
        echo "- $(date): The following log file didn't exist and is now created: $DIRECTORY.03.gz" >> $home/output/wlLogRotate.log
fi

if [[ ! -a ${DIRECTORY}.02.gz ]];
  then
    touch ${DIRECTORY}.02.gz
#Puts entry into log file.
        echo "- $(date): The following log file didn't exist and is now created: $DIRECTORY.02.gz" >> $home/output/wlLogRotate.log
fi

if [[ ! -a ${DIRECTORY}.01.gz ]];
  then
    touch ${DIRECTORY}.01
        touch ${DIRECTORY}.01.gz
#Puts entry into log file.
        echo "- $(date): The following log files didn't exist and are now created: $DIRECTORY.01 and $DIRECTORY.01.gz" >> $home/output/wlLogRotate.log
fi

#If all of the archived log files are there, then rotate them
if [[ -a ${DIRECTORY}.05.gz ]] && [[ -a ${DIRECTORY}.04.gz ]] && [[ -a ${DIRECTORY}.03.gz ]] && [[ -a ${DIRECTORY}.02.gz ]] && [[ -a ${DIRECTORY}.01.gz ]];

  then

#Log files
    cp -f ${DIRECTORY}.04.gz ${DIRECTORY}.05.gz
    cp -f ${DIRECTORY}.03.gz ${DIRECTORY}.04.gz
    cp -f ${DIRECTORY}.02.gz ${DIRECTORY}.03.gz
    cp -f ${DIRECTORY}.01.gz ${DIRECTORY}.02.gz
#Puts entry into log file.
        echo "- $(date): The following log files have been rotated: $DIRECTORY" >> $home/output/wlLogRotate.log

#Copy current log files
    cp -f ${DIRECTORY} ${DIRECTORY}.01
#Puts entry into log file.
        echo "- $(date): The following log files have been copied to version .01: $DIRECTORY" >> $home/output/wlLogRotate.log

#Remove the .01.gz files
        rm -f ${DIRECTORY}.01.gz
#Puts entry into log file.
        echo "- $(date): The following log .01.gz files have been removed: $DIRECTORY" >> $home/output/wlLogRotate.log

#Zip the log files
    gzip ${DIRECTORY}.01
#Puts entry into log file.
        echo "- $(date): The following .01 log files have been gziped: $DIRECTORY" >> $home/output/wlLogRotate.log

#Null out the working log files so that
#they go down to zero file size
    cat /dev/null > ${DIRECTORY}
#Puts entry into log file.
        echo "- $(date): The following log files have been nulled out: $DIRECTORY" >> $home/output/wlLogRotate.log

fi

done

Script to run node manager in background

Below is the script we can use to run Node manager in background

file1=$home/output/nodemgr10.out
file2=$home/output/nodemgr10.err
suffix=$(date +%s)
newfile1=$home/output/archive/nodemgr10.out.$suffix
newfile2=$home/output/archive/nodemgr10.err.$suffix
cp $file1 $newfile1
cp $file2 $newfile2
nohup $WL_HOME/server/bin/startNodeManager.sh 1>$file1  2>$file2 &

Thursday, May 21, 2015

Patching offline on Weblogic using BSU

1. Take Backup of Middleware home. In case of any problem after patching, we can revert whole Weblogic setup

2. Stop all java Processes  (Admin server/Mange servers and Node mannager if they are running). Also stop all process which are dependant on Weblogic setup.

3. cd $BEA_HOME/utils/bsu/cache_dir

a)rename patch-catalog.xml to some name which will be a backup file
b)Copy the patch with .jar extension to cache_dir(for ex: QR92.jar)
c)cp patch-catalog_15563.xml $BEA_HOME/utils/bsu/cache_dir/patch-catalog.xml

4. cd $BEA_HOME/utils/bsu/

./bsu.sh -view -prod_dir=$BEA_HOME/wlserver_10.3 -status=applied >/home/stelikep/zwblg202/zwblg202_applied_before_srv.txt

./bsu.sh -report  -bea_home=$BEA_HOME > ~/WS103_beforepatch.txt

./bsu.sh -prod_dir=$BEA_HOME/wlserver_10.3 -patchlist=E65J -verbose -install -log=~/zqsextraapda02_srv_E65J.txt

./bsu.sh -view -prod_dir=$BEA_HOME/wlserver_10.3 -status=applied > ~/zqsextraapda02_applied_after_srv.txt

./bsu.sh -report  -bea_home=$BEA_HOME > /home/lg400816/zqsextraapda02/WS103_afterpatch.txt

Once patching completed, we can start Weblogic processes.

Saturday, February 7, 2015

How to see the contents of cwallet.sso using Orapki

When using a file-based credential store with Oracle, credentials ultimately get stored in a wallet file (cwallet.sso).

Very little if any info exists on how to dump the contents of the wallet.  At best, most people leverage the trusty orapki command to get an overview of what’s inside as far as the maps and keys, but actual password information is never divulged.


Below is the command we will use to display the contents of cwallet.sso



./orapki wallet display -wallet Path/cwallet.sso

Sunday, February 1, 2015

Useful Unix commands

CD:
cd ~ : To go to home directory.

cd - : Switches from current path to previous path.

$head :   It displays the first n lines from the file.
  Syn: $head –n filename
  Ex: $head -10 userlist.txt

$comm: It displays common lines b/w 2 files.
  Syn:$comm file1 file2

xmllint: To read XML file in unix
xmllint --format AbInitioWebServicesConfig.xml

Zip files:
zcat: it is used for to open zip file in readable format.
   $zcat sample.gz

gzgrep: view the content of GZ file by using below command
gzgrep -i "merchRepNum:[0-9]" McsApplication.txt*

Grep:
1)grep -i Running filename  ---ignore casesenstive
       2----
       5----
     
2)grep –c Running filename –-- counts no of lines
               3

3)grep –n Running filename ---- prints along with line no’s.
              2:--------
              5:-------
           
4)grep -l Running *  -- list only files
       file1
       file2
       file3
     
5)grep -v "Server started" filename –-- It will print the lines which are not matches

fgrep: [faster grep]
It is used for to search multiple strings. But it doesn’t allow to search regular expressions.

Ex: fgrep "pavan
      >unix
      >linux " filename
It searches either pavan or unix or linux

egrep:[ Extended grep]
It is a combination of grep and fgrep
Ex: egrep "pavan
      >unix
      >linux " filename
egrep "^d" filename

Shell Scripting: Part 1

1. UNIX command should be in back cotes (`) in echo statement, otherwise it treats as a text.

bash-3.2$ echo "todays date is :`date`"
o/p-todays date is :Sun Feb  1 09:36:33 EST 2015
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

2. "Constant": It is a fixed value it doesn’t change during execution of the program.

$readonly a
When the variable is made readonly the shell doesn’t allow you to change their values.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

3. Shell script for doing simple arithmetic operations

Note1: Expr is a command to evaluating arithmatic expressions.But expr is capable of carrying out only integer arthematic.

Note2: *_ ? [] ---wild chard characters we will use “\”. And there be no space b/w this wild card character "\" and arithmetic operator as per below product expr ex: "expr $a \* $b"

Note3: Also there should be no space b/w variable and expression. There should be space b/w variables used in arithmetic operations. for ex: $a / $b

echo "enter 2 numbers"
read a b
c=`expr $a + $b`
echo "addition is $c"
e=`expr $a \* $b`
echo "product is $e"
f=`expr $a / $b `
echo "division is $f"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

4. Relational operators: -gt (>),- lt(<) ,- ge (>=),-le (<=),-eq(=),-ne(!=)

5.  Below are some variables which will help in scripting

$$ is the PID of the current process.

$? is the return code of the last executed command.

$# is the number of arguments in $*

$* is the list of arguments passed to the current process

Cut command R and D

Below is the content from a file called Userlist
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apache:x:48:48:Apache:/var/www:/sbin/nologin
dovecot:x:97:97:dovecot:/usr/libexec/dovecot:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
avahi-autoipd:x:100:156:avahi-autoipd:/var/lib/avahi-autoipd:/sbin/nologin
daniel:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. Select Column of Characters using Range
----------------------------------------
Range of characters can also be extracted from a file by specifying start and end position delimited with -. The following example extracts first 3 characters of each line from a file called userlist

bash-3.2$ cut -c1-3 userlist
apa
dov
nfs
ava
dan
------------------------------------------
Note: If you like to extract a some part of the output, you can combine option -f and -d. The option -f specifies which field you want to display, and the option -d specifies what is the field delimiter you are going to use to display the desired output

2. Select Column of Characters using either Start or End Position

Either start position or end position can be passed to cut command with -c option.
The following specifies only the start position before the ‘-’. This example extracts from 2nd character to end of each line from userlist file.

bash-3.2$ cut -c2- userlist
pache:x:48:48:Apache:/var/www:/sbin/nologin
ovecot:x:97:97:dovecot:/usr/libexec/dovecot:/sbin/nologin
fsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
vahi-autoipd:x:100:156:avahi-autoipd:/var/lib/avahi-autoipd:/sbin/nologin
aniel:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
-----------------------------------------------
3. Select a multiple Fields from a File

You can also extract more than one fields from a file or stdout. Below example displays username and home directory of users who has the login shell as “/sbin/nologin”.

bash-3.2$ grep "/sbin/nologin" userlist | cut -d':' -f1,6
apache:/var/www
dovecot:/usr/libexec/dovecot
nfsnobody:/var/lib/nfs
avahi-autoipd:/var/lib/avahi-autoipd
daniel:/home/sabayon
--------------------------------------------------

Monday, January 12, 2015

How to configure Weblogic with Iplanet

1. Login into iplanet console http://hostname:port/
2. Click on Configuration and Click on new button
3. In the new window, Provide details as mention below
4. Name: Name of the configuration, we can give our desired name ( ex: krishna-secure)
   Server Name: Name of the instance (Eg: https-krishna-secure)
   Document Root: Root folder for the instance (Eg: /apps/Docroot/krishna-secure)
   Server user : username of the server
5. Then click om Next button. Provide port number and IP address as * then click on next button
6. In next step, it will ask details for enabling java and regarding CGI and others. leave the default configuration as it is. No need to change anything.
7. In the Next screen, Select the available Node “krishna.mycomp.com”  and Click on Add then  Click on next
8. In the next screen we will see all the details we have entered previously for review and then click on finish button and then close button.
9. Now in the admin console, Click on Configurations tab. You can see the newly created instance.
10. Select the newly created instance and click on Deploy.
11. After clicking on deploy button you will see a popup window and click on deploy button in popup window.
12. After click on deploy button in popup window , In next step/window click on close button.
13. Now, select the newly created instance and click on Start Running.
14. To avoid the hostname conflict issues in instance configuration while starting instance, Update the hostname of server with existed entries in HTTP listener and Virtual Servers configuration.

Now we need to configure SSL and Weblogic proxy settings at Iplanet end.

1) Go to the newly created instance config directory
/apps/instances/https-krishna-secure/config
2) Open magnus.conf file add below lines and save the file
Init fn="load-modules" shlib="/apps/iplanet/lib/mod_wl.so"
Init fn="load-modules" shlib="libj2eeplugin.so" shlib_flags="(global|now)"
KernelThreads off
3) Open obj.conf, add the context path details of weblogic application like below.
<Object name="weblogic" ppath="*/krishnaapp/*">
Service fn="wl_proxy" WebLogicCluster="hostname1:port,hostname2:port,hostname3:port" PathTrim="/krishnaapp" PathPrepend="/Krishna_APPWL" WLProxySSL="ON" SecureProxy="ON" RequireSSLHostMatch="false" TrustedCAFile="/app/certs/hostnametrustedcas.pem" Debug="ERR" WLLogFile="/app/wlpluginlogs/wlproxy-krishna.log" WLTempDir="/app/wlpluginlogs" DebugConfigInfo="OFF"
</Object>

4) After changing the obj.conf and magnus.conf file you can see the in admin console as “Instance Configuration Modified”. To get reflect these change, deploy the changes on instance.
5) Generate the Iplanet certs with extension of .db, copy the same in config folder.
6)Go to admin console deploy the changes. Click on instance in admin console. Click on “HTTP Listeners”. Click on “http-listener-1”. Then click on SSL. Then click on “set passwords” button in next step/window. After clicking on “Set Passwords ” button, Please provide password and then click ok and close.
7) After clicking on Close button, Select SSL “Enabled” and “Server-cert” from dropdown. Click on Apply and close button.
8) Select “Deployment Pending” as top of screen .Select “Pull and deploy configuration from ” and click on ok.
9. Add the below parameters in server.xml to bypass starting of iplanet instance.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<pkcs11>
  <token>
    <name>internal</name>
    <pin>password</pin>
  </token>
</pkcs11>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10. Now start the instance.

Sunday, January 11, 2015

Core dump is getting generated in weblogic managed servers machines of 10.3 domain

We have a weblogic domain in which we have 3 weblogic servers configured in horizontal clustering mode. From last few months Core dumps are getting generated(by throwing below error) @ different times on 3 machines where weblogic managed servers are resided. and the process getting killed after core dump getting generated and node manager is starting the killed process. All this process happening with in 5 minutes.
======================================
# An unexpected error has been detected by Java Runtime Environment:
#  SIGSEGV (0xb) at pc=0xfee15cf0, pid=*****, tid=40
# Java VM: Java HotSpot(TM) Server VM (10.0-b19 mixed mode solaris-sparc)
# Problematic frame:
# V  [libjvm.so+0x615cf0]
=====================================

By default Coredump files on Solaris are generated in the directory "/var/core/". But we have customized, so that it will get generated in domain home directory.

Then I have started to analyze the core dump using pstack and got the below output for a thread 40.

 ff29e8cc _lwp_kill (6, 0, ff317080, ff27de54, ffffffff, 6) + 8
 ff212950 abort    (2cf80, 1, fee76768, ffba0, ff315518, 0) + 110
 fee6d5c4 __1cCosFabort6Fb_v_ (1, ff1014f4, 1, ff0ea000, 174f4, 17400) + 5c
 fef66c18 __1cHVMErrorOreport_and_die6M_v_ (ff121ff0, 0, 1, ff0b261f, fef73bd2, 17400) + d1c
 fe9a5dc8 JVM_handle_solaris_signal (b, a8b3d8f0, a8b3d638, 8b000, 306400, fee15cf0) + a64
 fe9a7f50 __1cNCompileBrokerZinvoke_compiler_on_method6FpnLCompileTask__v_ (1b93ef0, e8400, 50, 0, fe9a7140, 306400
 fea24e94 __1cNCompileBrokerUcompiler_thread_loop6F_v_ (0, ff120fe0, 306400, 2ff210, 2c800, 2c800) + 65c
 fef16e74 __1cKJavaThreadRthread_main_inner6M_v_ (306400, 3068c0, 28, f, ff0ea000, 0) + 48
 --------------------------

Didn't understand exactly generated core using pstack command, So I have tried with "pflags" command, got the below output

 core 'core' of 29912:   /app/rsf/bea10/jdk160_05/bin/java -Dweblogic.Name=WLSVRname -Dbea.home data model = _ILP32  flags = MSACCT|MSFORK
 /40:   flags = DETACH
        sigmask = 0xfffffeff,0x0000ffff  cursig = SIGABRT
  /42:   flags = DETACH|STOPPED  pollsys(0x4,0x0,0xa8a1f948,0x0)
        why = PR_SUSPENDED  sigmask = 0x00000004,0x00000000

Now I got to know that thread 40 has received the SIGNAL "SIGABRT" (The SIGABRT signal is sent to a process to tell it to abort, i.e. to terminate. The signal is usually initiated by the process itself when it calls abort function, but it can be sent to the process from outside as well as any other signal.) I am not sure why SIGABRT was generated in Thread 40. Is it because of the code which I have mentioned above(thread 40) where analyzed pstack command, I am not sure.
----------------------------------------------------------------

As I didn't find the exact reason with pflags, I used another command "pmap". The "pmap" command display information about the address space of a process, in this case the program that causes the coredump.
Using pmap command, getting the below output, still I am not able to find the RCA.
A76C0000      16K r-x--  /app/rsf/bea10/wlserver_10.3/server/native/solaris/sparc/libnodemanager.so
A76D2000       8K rwx--  /app/rsf/bea10/wlserver_10.3/server/native/solaris/sparc/libnodemanager.so
A7780000       8K r-x--  /app/rsf/bea10/wlserver_10.3/server/native/solaris/sparc/libwlfileio2.so

Still working on the same, Will post soon the root cause of the issue.