Search Results


Saturday, February 20, 2016

Unix Tips

Unix Tips


# These commands gets executed when the use logs in the shell
# File path: $home/.bashrc

# Setting Path
export PATH=/u01/app/oracle/products/jdk1.8.0_66/bin:$PATH

# Setting variables
DHOME=/u01/app/oracle/config/domains/soa_domain
export DHOME

LOGS=/u01/app/oracle/config/domains/soa_domain/servers/SOA1/logs
export LOGS

# Settings aliases
alias domain='cd /u01/app/oracle/products/jdk1.8.0_66/bin'


Other useful commands


# List out running processes
ps -ef | grep java

# Push a foreground process into background
^z ; # suspends the foreground process
bg ; # pushes suspended process into background process

# zip and unzip folders
zip -r soasit_domain_bkp.zip soasit_domain
unzip filename.zip

# Find a text in files
find . "*.xml" | xargs grep -il "searchText"

# Matching any line which start with echo egrep '^(( )+|( )?)echo' filename

# Monitoring Log files
tail -100f filename

# Set putty title
echo -e "\033]0; `hostname` \007\c"

# Color ls
alias l='ls --color=auto -lrt'

# Change the date stamp on the file
touch -r referenceFile filename


# Cpu usage
top

#Query Memory info
Total Memory: grep MemTotal /proc/meminfo
Swap Space: grep SwapTotal /proc/meminfo
Shared Memory: df -k /dev/shm/
Free Memory: free

#Find system details
Processor info: grep "model name" /proc/cpuinfo
System Architecture: uname -m
Disk Space: df -h
Linux version: cat /proc/version
Kernel Version: uname -r
Hostname: hostname




Users and Groups



# Add user and groups
/usr/sbin/useradd -g oinstall -G dba oracle
/usr/sbin/groupadd oinstall

#To change the Password: 
passwd

#Display user details: 
id oracle


# Assign user group and groups

/usr/sbin/usermod -g oinstall -G dba oracle

# Change Path for all users
/etc/profile



Tar

tar cvzf foo.tgz *.cc *.h This creates (c) a compressed (z) tar file named foo.tgz (f) and shows the files (v). tar cvzf foo.tgz cps100 >> will tar the directory cps100 tar tzf foo.tgz >>To see a tar file's table of contents tar xvzf foo.tgz >> To extract the contents of a tar file This untars/extracts (x) into the directory, prints the files (v). tar xvzf foo.tgz anagram.cc You can extract only one (or several) files

Vi Scripts

To repalace the last occuring character "/" with Tab :%s,/\([^/]*$\),\t\1, Eg: /home/prasanna/temp/hill.txt results in /home/prasanna/temp hill.txt

Finding files in Linux based on time

find . -name "hello" -printf "%a %c %t %f \n" find . -follow \( -mtime 2 -o -mtime +2 \) -print %a - access time (reading, coping) %c - Changed time of file parameters or properties %t - modify time of file content %f - filename without dirs -atime n - accessed n days ago -mtime n - modified n days ago -ctime n - changed n days ago

# Find and delete files older than a day

find . -mtime +1 -exec rm {} \;



Connectivity


#Telnet to test host port 
telnet hostname port

#Alternative to telnet
nc -zv hostname port

#Could be used to test connectivity as well
openssl s_client -connect smtp.gmail.com:465

#Local port forwarding
ssh -L 2521:destinationhost:1521 remotehost

#Remote port forwarding
ssh -R 2521:destinationhost:1521 remotehost

#Forwarding GUI programs
ssh -X remotehost

To learn more about port forwarding check 
https://help.ubuntu.com/community/SSH/OpenSSH/PortForwarding





FTPs (FTP over ssl)


Commands to transfer files to FTPs server (also called as FTP over ssl). 

#upload file
curl -v --user username:password --ftp-ssl  -k ftp://Ftp_Hostname:21/home/folder1/ -T TestFile

#List files
curl --user username:password --ftp-ssl -l  -k ftp://Ftp_Hostname:21/home/folder1/*

#Download file
curl --user username:password --ftp-ssl  -k ftp://Ftp_Hostname:21/home/folder1/TestFile -o TestFile

#Delete file
curl -v --user username:password --ftp-ssl  -k ftp://Ftp_Hostname:21/home/folder1/ -Q "DELE /home/folder1/TestFile"




Tuesday, February 16, 2016

Useful xslt code

How to convert XML list into comma seperated list


 <xsl:for-each select="/ns0:UserId">
            <xsl:text>'</xsl:text>
            <xsl:value-of select="."/>
            <xsl:text>'</xsl:text>
            <xsl:if test="position() != last()">
              <xsl:text>,</xsl:text>
            </xsl:if>
          </xsl:for-each>

Example:

<UserId>1</UserId>
<UserId>2</UserId>
<UserId>3</UserId>

Into
'1','2','3'


How to strip of empty elements from xml


This xslt code work with any XML types, so it could be saved in a common location and used everywhere.

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="fn xs">
        <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
        <xsl:template match="node()|@*">
                <xsl:if test="normalize-space(string(.)) != ''">
                        <xsl:copy>
                                <xsl:apply-templates select="node()|@*"/>
                        </xsl:copy>
                </xsl:if>
        </xsl:template>
</xsl:stylesheet>


How to find distinct values and group in XSLT

This xslt will groups the xml elements by distinct UserID

 <xsl:key name="UserId" match="/ns0:queryResponse/ns0:QueryResults/ns0:records/ns0:UserId/text()"
           use="."/>
  <xsl:template match="/">
    <tns:TransformationResults>
      <xsl:for-each select="/ns0:queryResponse/ns0:QueryResults/ns0:records/ns0:UserId/text()[generate-id() = generate-id(key('UserId',.)[1])]">
        <tns:User>
          <tns:UserId>
            <xsl:value-of select="."/>
          </tns:UserId>
          <xsl:call-template name="getResponsibility">
            <xsl:with-param name="UserId" select="."/>
            <xsl:with-param name="records" select="/ns0:queryResponse/ns0:QueryResults/ns0:records"/>
          </xsl:call-template>
        </tns:User>
      </xsl:for-each>
    </tns:TransformationResults>
  </xsl:template>
  <xsl:template name="getResponsibility">
    <xsl:param name="UserId"/>
    <xsl:param name="records"/>
    <xsl:for-each select="$records[ns0:UserId/text() = $UserId]">
      <tns:Responsibility>
        <tns:ResponsibilityId>
          <xsl:value-of select="ns0:rId"/>
        </tns:ResponsibilityId>
        <tns:ResponsibilityName>
          <xsl:value-of select="ns0:rName"/>
        </tns:ResponsibilityName>
      </tns:Responsibility>
    </xsl:for-each>
  </xsl:template>
 

Input 


<records>
<UserId>1</UserId>
<rId>1001</rId>
<rName>Responsibility1</rName>
</records>
<records>
<UserId>1</UserId>
<rId>1002</rId>
<rName>Responsibility2</rName>
</records>
<records>
<UserId>2</UserId>
<rId>1001</rId>
<rName>Responsibility1</rName>
</records>
<records>
<UserId>2</UserId>
<rId>1002</rId>
<rName>Responsibility2</rName>
</records>

Output

<TransformationResults>
<User>
<UserId>1</UserId>
<Responsibility>
<ResponsibilityId>1001</ResponsibilityId>
<ResponsibilityName>Responsibility1</ResponsibilityName>
</Responsibility>
<Responsibility>
<ResponsibilityId>1002</ResponsibilityId>
<ResponsibilityName>Responsibility2</ResponsibilityName>
</Responsibility>
</User>
<User>
<UserId>2</UserId>
<Responsibility>
<ResponsibilityId>1001</ResponsibilityId>
<ResponsibilityName>Responsibility1</ResponsibilityName>
</Responsibility>
<Responsibility>
<ResponsibilityId>1002</ResponsibilityId>
<ResponsibilityName>Responsibility2</ResponsibilityName>
</Responsibility>
</User>
</TransformationResults>



List out all the XML elements

I needed this for XSD documentation work. Generate a sample XML from the xsd and use that as  input to this xslt. It prints out all the elements in xpath format relative to root element.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="text" indent="no" />

    <xsl:template match="*[not(*)]">
   <xsl:text>response</xsl:text>
        <xsl:for-each select="ancestor-or-self::*">
            <xsl:value-of select="concat('.', substring-after(name(),':'))"/>

            <xsl:if test="count(preceding-sibling::*[name() = name(current())]) != 0">
                <xsl:value-of select="concat('[', count(preceding-sibling::*[name() = name(current())]) + 1, ']')"/>
            </xsl:if>
        </xsl:for-each>
        <xsl:text>&#xA;</xsl:text>
        <xsl:apply-templates select="*"/>
    </xsl:template>

    <xsl:template match="*">
        <xsl:apply-templates select="*"/>
    </xsl:template>

</xsl:stylesheet>

Friday, February 12, 2016

Configure Weblogic ODL logger

How to configure weblogic ODL logger

Log files in the weblogic server could be managed using Log Configuration UI in the enterprise manager console (em console). We could configure rotation policies and log levels etc straight from the UI. Here are the steps to configure a custom ODL logger.

Steps

  • Goto em console http://host:port/em
  • Navigate to WebLogic Domain > DefaultDomain > DefaultServer
  • Rightclick on DefaultServer and select Logs > Log Configuration
  • Log Levels tab allows for log level configuration
  • Choose "Loggers with persistant log level state"
  • Scroll down to the bottom of the page and expand "Specify Loggers"
  • Enter the name of the class "pras.soa.business" and choose log level (e.g. INFO)
  • Click on Apply button to save the settings.

  • Log files tab lets the user configure the log file handler for the selected log levels
  • Click on Create button
  • Enter the following details
    • Name: prasloghandler
    • Log path: ${domain.home}/servers/${weblogic.Name}/logs/${weblogic.Name}-pras.log
    • Log Level: INFO
    • Loggers to associate: pras.soa.business
    • Choose a rotation policy based on your needs.
  • Click ok to finish.



Now everytime when a class in pras.soa.business package uses java logging, it gets logged in the DefaultServer-pras.log file.

Here is an example java code

Java Example

//Import
import java.util.logging.Logger;

//Class variables
private static final Logger log = Logger.getLogger("pras.soa.business.test");


//Code in methods
log.info("this is a test")