Search Results


Tuesday, November 29, 2016

Import certificates using keytool

Keytool


One of the import step to call an https webservice using java is to import the SSL certificates before initiating a call.

This example shows the certificates imports on a default weblogic certificates path. However this could be different on your weblogic server, so make sure the path is checked before installing the certificates.


cd /u01/app/oracle/products/jdk1.8.0_66/bin

Install
./keytool -import -keystore /u01/app/oracle/products/fmw1213/wlserver/server/lib/DemoTrust.jks -alias salesforcecom_test -storepass DemoTrustKeyStorePassPhrase -file ~/SalesforceCert.cer

Verify
keytool -list -keystore /u01/app/oracle/products/fmw1213/wlserver/server/lib/DemoTrust.jks -storepass DemoTrustKeyStorePassPhrase -alias salesforcecom_test

Notepad++ plsql function list


Locate functionList.xml file on the Notepad++ install location.

Add association map

<association langID="17" id="sql_node"/>


And the following parser

<parser id="sql_node" displayName="SQL Node" commentExpr="((/\*.*?\*)/|(--.**$))">
    <function
            mainExpr="^[\s]{0,}(function|procedure|--[1-9])[\s]{1,}[\w_]{1,}">
            <functionName>
                  <nameExpr expr="^[\s]{0,}(function|procedure|--[1-9])[\s]{1,}\K[\w_]{1,}"/>
            </functionName>
    </function>
</parser>

And finally restart the Notepad++

Now enable View -- FunctionList

This should bring you list of all functions and procedures in the current sql or plsql file.

You can click on it to navigate to selected code block.

How to deploy XML publisher report to R12

XML Publisher deployment



To deploy concurrent program and request groups follow this link (FNDLOAD).

Deploy XMLP Entries

Following creates metadata for the XML publisher data definition and the associated template. This entries have to be created before uploading the actual files.

FNDLOAD apps/apps O Y DOWNLOAD  $XDO_TOP/patch/115/import/xdotmpl.lct XXC_CUSTOM_S.ldt XDO_DS_DEFINITIONS APPLICATION_SHORT_NAME='XXC' DATA_SOURCE_CODE='XXC_CUSTOM' TMPL_APP_SHORT_NAME='XXC' TEMPLATE_CODE='XXC_CUSTOM'



FNDLOAD apps/apps O Y UPLOAD $XDO_TOP/patch/115/import/xdotmpl.lct CUSTOM.ldt


Deploy RTF


java oracle.apps.xdo.oa.util.XDOLoader \
UPLOAD -DB_USERNAME $APPS_UN \
-DB_PASSWORD $APPS_PW -JDBC_CONNECTION \
$DB_IP_ADDR:$DB_PORT_NO:$APPS_INS \
-LOB_TYPE TEMPLATE -LOB_CODE XXCUSTOM_CODE \
-APPS_SHORT_NAME $XXC -LANGUAGE 'en' \
-XDO_FILE_TYPE 'RTF' -FILE_CONTENT_TYPE 'application/rtf' \
-lct_FILE $XDO_TOP/patch/115/import/xdotmpl.lct \
-LOG_FILE LXXCUSTOM.log \
-FILE_NAME $LOAD_DIR/XXCUSTOM.rtf \
-CUSTOM_MODE FORCE


Deploy XLS



java oracle.apps.xdo.oa.util.XDOLoader \
UPLOAD \
-DB_USERNAME $APPS_UN \
-DB_PASSWORD $APPS_PW \
-JDBC_CONNECTION $DB_IP_ADDR:$DB_PORT_NO:$APPS_INS \
-LOB_TYPE TEMPLATE \
-APPS_SHORT_NAME $XXC \
-LOB_CODE XXCUSTOM_CODE \
-LANGUAGE en \
-TERRITORY 00 \
-NLS_LANG American_America.AL32UTF8 \
-XDO_FILE_TYPE XLS \
-FILE_CONTENT_TYPE application/rtf \
-FILE_NAME XXCUSTOM.xls \
-LOG_FILE L_XXCUSTOME.log     -CUSTOM_MODE FORCE


Deploy Data template



java oracle.apps.xdo.oa.util.XDOLoader \
UPLOAD \
-DB_USERNAME $APPS_UN \
-DB_PASSWORD $APPS_PW \
-JDBC_CONNECTION $DB_IP_ADDR:$DB_PORT_NO:$APPS_INS \
-LOB_TYPE DATA_TEMPLATE \
-APPS_SHORT_NAME $XXC \
-LOB_CODE XXCUSTOMER_CODE \
-LANGUAGE en \
-TERRITORY 00 \
-NLS_LANG American_America.AL32UTF8 \
-XDO_FILE_TYPE XML-DATA-TEMPLATE \
-FILE_CONTENT_TYPE text/xml \
-FILE_NAME XXCUSTOM.xml \
  -LOG_FILE L_XXCUSTOM.log       -CUSTOM_MODE FORCE



Friday, October 21, 2016

Bounce R12 apache server


Restart R12 apache server


Stop Server
sh $INST_TOP/admin/scripts/adoacorectl.sh stopall

Start Server
sh $INST_TOP/admin/scripts/adoacorectl.sh startall

Check Server status
sh $INST_TOP/admin/scripts/adoacorectl.sh status -l


Clear HTML cache :

# Stop the server
cd $ADMIN_SCRIPTS_HOME
./adopmnctl.sh stopall
./adoacorectl.sh status  -l  
cd $COMMON_TOP/_pages
# Here are the java classes to clear.
ls -l (Check the files)
rm *

# Compile the jsp files
cd $FND_TOP/patch/115/bin
ojspCompile.pl --compile --flush -p 10
cd $COMMON_TOP/_pages
ls -l (Check the files)

# Start the server again
cd $ADMIN_SCRIPTS_HOME
./adopmnctl.sh startall
./adoacorectl.sh status  -l

Thursday, September 29, 2016

Oracle apps R12: Useful profile option

Some useful R12 Profile Options


Output/Log Viewer

This option makes the concurrent program output to be opened in the internet explorer rather than form window.

Profile Option Name: Viewer: Text      
User: Value: browser


About this page: link

It enabled the "About this Page" link at the bottom of any OAF page. This link helps to find more information about the OA Framework page.

Profile Option Name: FND: Diagnostics 
User: Value: Yes


Forms Diagnostics

To get Diagnostics menu in forms use the following profile option

Profile Option Name: Hide Diagnostics menu entry
User Value: No

Profile Option Name: Utilities:Diagnostics
User Value: Yes


Session Timeout

This one lets the user stay logged-in longer.

Profile Option Name: ICX: Session Timeout
User Value (in Minutes): 180 


ICX: Limit time


This profile option defines the maximum connection time for a connection – regardless of user activity.
If 'ICX:Session Timeout' is set to NULL, then the session will last only as long as 'ICX: Limit Time', regardless of user activity.

Profile Option Name: ICX: Limit time
User Value (in Hours): 4



Wednesday, September 28, 2016

Jdeveloper Salesforce Adapter error

This version of the client is no longer supported


One fine day I opened the jdeveloper and added a new salesforce adapter component. I selected the wsdl and entered the username, password+security key and then "booom!!".

A nasty error message "This version of the client is no longer supported.".





What the heck is wrong with jdeveloper, you worked fine for years and why are you doing this now? grrr!!.

Would you ever give me a meaningful error message?!!

Solution


After a bit of research it is same problem we had with the server. Salesforce has disabled TLSv1.0 for all the SSL communications. (Find out more information about this here SalesForce TLS 1.0 has been disabled)

Luckily the solution is simple, just add  the following in your ../jdeveloper/jdev/bin/jdev.conf file:
AddVMOption -Dhttps.protocols=TLSv1.1 


And restart the Jdeveloper.

Note: This solution should work on both Jdev 12c and 11g

Tuesday, August 23, 2016

Automatic java mouse mover

There are many solutions to moving mouse automatically to keep the screen active in windows.

For java programmers, simple solution is to write a java program to move the mouse automatically.


package movemouse;

import java.awt.MouseInfo;
import java.awt.PointerInfo;
import java.awt.Robot;

import java.util.Random;

public class moveMouse {
    public moveMouse() {
        super();
    }

    public static final int WAIT = 60 * 1000; // SECONDS
    public static final int OFFSET = 3;

    public static void main(String... args) throws Exception {
        int x, y;
        Robot robot = new Robot();
        Random random = new Random();
        PointerInfo a;

        while (true) {

            a = MouseInfo.getPointerInfo();
            x = (int) a.getLocation().getX();
            y = (int) a.getLocation().getY();
            robot.mouseMove(+ OFFSET, y + OFFSET);
            Thread.sleep(WAIT);

            a = MouseInfo.getPointerInfo();
            x = (int) a.getLocation().getX();
            y = (int) a.getLocation().getY();
            robot.mouseMove(- OFFSET, y - OFFSET);
            Thread.sleep(WAIT);
        }
    }
}



Compile and Enjoy!

If you don't have jdk use this jar file (moused.jarred). Open the link and clikc on Download button to download the file and then rename it to jar. Use the following command to execute it.

java -jar moused.jar

Thursday, August 18, 2016

Some Useful FNDLOAD commands

Following are some of the useful commands to migrate WEBADI, Concurrent programs and request set link in EBS R12.

WEB ADI or Oracle Data Integrator


FNDLOAD apps/apps 0 Y DOWNLOAD $BNE_TOP/patch/115/import/bneintegrator.lct ldt_file_xintg.ldt BNE_INTEGRATORS INTEGRATOR_ASN="XXC" INTEGRATOR_CODE="TEST_XINTG"


FNDLOAD apps/apps 0 Y UPLOAD $BNE_TOP/patch/115/import/bneintegrator.lct ldt_file_xintg.ldt

Concurrent Programs


Concurrent program download also extracts the Executables and value sets along with it.

FNDLOAD apps/apps O Y DOWNLOAD $FND_TOP/patch/115/import/afcpprog.lct $program.ldt PROGRAM APPLICATION_SHORT_NAME=XXA CONCURRENT_PROGRAM_NAME=$program


FNDLOAD apps/apps 0 Y UPLOAD $FND_TOP/patch/115/import/afcpprog.lct XXtestfile.ldt WARNING=YES UPLOAD_MODE=REPLACE CUSTOM_MODE=FORCE


Request set and links


These commands will export both Request set and request set links.

FNDLOAD apps/apps 0 Y DOWNLOAD $FND_TOP/patch/115/import/afcprset.lct testfile.ldt REQ_SET_LINKS REQUEST_SET_NAME='XXTEST_REQ_SET'



FNDLOAD $APPS_UN/$APPS_PW 0 Y UPLOAD @FND:patch/115/import/afcprset.lct $LDT_DIR/testfile.ldt UPLOAD_MODE=REPLACE CUSTOM_MODE=FORCE


FND Messages


Following command will download and load fnd messages.

FNDLOAD apps/$APPS_PW 0 Y DOWNLOAD $FND_TOP/patch/115/import/afmdmsg.lct messages_file.ldt FND_NEW_MESSAGES APPLICATION_SHORT_NAME="XXC" MESSAGE_NAME="MESSAGE_NAME"


FNDLOAD apps/$APPS_PW 0 Y UPLOAD $FND_TOP/patch/115/import/afmdmsg.lct XXC_UBM_HR_DEDUCTION_CODE_MISS.ldt WARNING=YES UPLOAD_MODE=REPLACE CUSTOM_MODE=FORCE







Tuesday, June 28, 2016

SalesForce - TLS 1.0 has been disabled - Oracle SOA BPEL webservice

One fine day all of a sudden I started getting the following errors from all the web-services trying to connect to the SalesForce system.

Client received SOAP Fault from server : UNSUPPORTED_CLIENT: TLS 1.0 has been disabled in this organization. Please use TLS 1.1 or higher when connecting to Salesforce using https.

Ok, the SalesForce system was upgraded over the weekend. And one of the upgrades was to stop supporting TLS 1.0 and only support TLS 1.1 or higher version of SSL protocols.


Question:


How do we upgrade Oracle SOA web services to support TLS 1.1 or higher? 
Where does this  settings resides and how do we change it?

What a nightmare!

Luckily this is something that Java 7 supports, Phew! And it is just a matter of setting the system param

-Dhttps.protocols=TLSv1.1,TLSv1.2

or code as

System.setProperty("https.protocols", "TLSv1.1,TLSv1.2");

in your java program before calling the webservice.

How to change it in Oracle SOA?

  • Login to SOA server (windows/Unix)
  • Goto Domain home and then cd bin
  • vi setSOADomainEnv.sh
    • and past the following content at the end of the file
EXTRA_JAVA_PROPERTIES="${EXTRA_JAVA_PROPERTIES} -Dhttps.protocols=TLSv1.1,TLSv1.2"
export EXTRA_JAVA_PROPERTIES
  • Now bounce the SOA managed servers.
  • If you have a clustered server then remember to do it on all the nodes.
  • This solution works on Oracle SOA 12.1.3



Friday, May 06, 2016

Weblogic Tips

Some common weblogic tasks


Setting CLASSPATH


in Windows

Append the following lines to the file $DOMAIN_HOME/bin/setDomainEnv.cmd
CLASSPATH=%CLASSPATH%;%DOMAIN_HOME%/Properties


in Unix

Append the following lines to the file $DOMAIN_HOME/bin/setDomainEnv.sh
CLASSPATH="${CLASSPATH}${CLASSPATHSEP}${DOMAIN_HOME}/Properties"
export CLASSPATH


Normally files stored in the domain home could be accessed without having to set class path, this example is just for illustration.

Setting Boot.properties


You could set username and password in the properties files so that you dont have to enter weblogic credentials every time the server is started. It has to be done for every server

create a folder security under $domain_home/servers/AdminServer
create a new file boot.properties and enter the following

username=weblogic
password=welcome1

The clear text password will be automatically changed to encrypted one when the weblogic starts up for the first time


Script to Start and Stop servers


Startup Script

#!/bin/bash

cd /d01/fmw1213/oracle_common/common/bin

./wlst.sh<<ThisIsTheEnd
nmConnect('nodemanager','welcome1','wlHostname','5556','soa_domain','/u01/app/oracle/config/domains/soa_domain')
nmStart('AdminServer')

ThisIsTheEnd

exit 0


Shutdown Script

#!/bin/bash

cd /d01/fmw1213/oracle_common/common/bin

./wlst.sh<<ThisIsTheEnd
nmConnect('nodemanager','welcome1','wlHostname','5556','soa_domain','/u01/app/oracle/config/domains/soa_domain')
nmKill('AdminServer')

ThisIsTheEnd

exit 0




Script to Start and Stop NodeManager

Startup Script

#!/bin/bash

cd /d01/fmw1213/oracle_common/common/bin

./wlst.sh<<ThisIsTheEnd

startNodeManager(verbose='true',NodeManagerHome='/d01/fmw1213/config/domains/soa_domain/nodemanager',ListenPort='5556',ListenAddress='wlHostname')

ThisIsTheEnd

exit 0


Shutdown Script

#!/bin/bash

cd /d01/fmw1213/oracle_common/common/bin

./wlst.sh<<ThisIsTheEnd

nmConnect('nodemanager','welcome1','wlHostname','5556','soasit_domain','/d01/fmw1213/config/domains/soa_domain')
stopNodeManager()


ThisIsTheEnd

exit 0



Managing Log files


Refer this link


Decrypt Weblogic passwords


Refer this link


How to increase heap space and permgen space?


Refer this link




Wednesday, May 04, 2016

Testing network connectivity from Salesforce

One of the challenges with consuming the web-service from SalesForce is that lack of tools, like telnet and ping, to test the network connectivity.

But luckily we code execute anonymous code in SalesForce from Developer console. Here are the steps to test web-service from sales-force.

Register URL 


All the URLs must be registered in SalesForce remote site settings before being called by the code.

  • Go to Setup > Security Controls > Remote Site Settings
  • Click on New Remote Site, enter the following and click Save
    • Remote Site Name: XX_TEST
    • Remote Site URL: http://domainhost/
  • Click Save


SalesForce Test Code


  • Go to the Developer Console 
  • Navigate Debug > Open Execute Anonymous Window  (Ctrl + E)
  • Execute the following code
  • Logs should show up in the Query Results Window


String soapEndpoint = 'https://blabla/test';
String soapBody = 'soap envelope';

HttpRequest req = new HttpRequest();
Http http = new Http();
HttpResponse resp = new HttpResponse();
req.setEndpoint(soapEndpoint);

//add Request header
req.setMethod('POST');
req.setHeader('Content-type', 'text/xml; charset=utf-8');
req.setHeader('SOAPAction', 'namesspace for wsdl');
req.setBody(soapBody);
System.debug(soapBody);

// add the endpoint to the request
try {
System.debug('Sending request');
resp = http.send(req);
System.debug(resp.toString());
System.debug(resp.getBody());
}  catch(System.CalloutException e) {
System.debug('Callout error: '+ e);
}

Friday, April 29, 2016

SOA Composite management commands

SOA Suite Utilities

These are some of the useful wlst commands to manage SOA composites. These are better alternatives to navigating the EM console for SOA management tasks.

Before executing these commands set the JAVA_HOME and path variables for wlst commands to work. If your using unix or linux then use linux syntax for setting path variable and java_home and then run wlst.sh under the same oracle path.

Open cmd and enter the following

  • set JAVA_HOME=C:\UBM\Programs\jdk1.7.0_79
  • set path=C:\UBM\Programs\jdk1.7.0_79\bin;C:\Oracle\Middleware12c\Oracle_Home\oracle_common\modules\org.apache.ant_1.9.2\bin;%PATH%
  • cd C:\Oracle\Middleware12c\Oracle_Home\soa\common\bin
  • ./wlst.sh or wlst.cmd

Starts SCA composite

sca_startComposite('hostname', '8001', 'weblogic', 'welcome1', 'TestSCAProcess', '1.0', partition='default')

Stops SCA composites

sca_stopComposite('hostname', '8001', 'weblogic', 'welcome1', 'TestSCAProcess', '1.0', partition='default')

Undeploy SCA composites

sca_undeployComposite("http://hostname:8001", "HelloWorld", "1.0", user="weblogic", password="welcome1",partition='myPartition')

Lists all SOA composites

sca_listDeployedComposites('hostname', '8001', 'weblogic', 'welcome1')

Assign Default composite

Sets a SOA composite application revision as the default version. This revision is instantiated when a new request comes in.
sca_assignDefaultComposite("hostname", "port", "weblogic", "welcome1","HelloWorld", "1.0", partition='myPartition')

Delete MDS files

# This command will delete all the files under /apps directory in mds.
connect('weblogic', 'welcome1', 't3://localhost:7101');
deleteMetadata(application='soa-infra',server='DefaultServer',docs='/apps/**');








Wednesday, April 20, 2016

How to increase JVM memory in Weblogic


There are two OutOfMemoryError that the weblogic server might throw if the memory settings are not tuned.


  •  java.lang.OutOfMemoryError: Java heap space
    • The heap space error could be fixed by tunning Xms (minimum heap space) and Xmx (maximum heap space) parameters
  •  java.lang.OutOfMemoryError: PermGen space
    • And perm gen error could be fixed by tunning the PermSize parameter.



How to change memory settings in weblogic


There are many ways to change it and no of the standard ways is to change the setDomainEnv.sh file and append the following lines at the end of the file.

Remember to restart the server for this setting to take effect.

echo "******Custom Memory Settings for UBM SOA servers******"
echo "Server Name ${SERVER_NAME}"
echo "Memory Arguments  ${MEM_ARGS}"


if [ "${SERVER_NAME}" = "WLS_SERVER1" ] ; then
        MEM_ARGS=" -Xms1024m -Xmx3584m -XX:PermSize=512m -XX:MaxPermSize=1536m "
        export MEM_ARGS
fi


if [ "${SERVER_NAME}" = "AdminServer" ] ; then
        MEM_ARGS=" -Xms1024m -Xmx2584m -XX:PermSize=512m -XX:MaxPermSize=1536m "
        export MEM_ARGS
fi



How to verify


Run the ps -ef command in unix/Linux to check if the paratemers are passed correctly to the jvm

ps -ef | grep java | cut -c 1-200


And you can also see the actual memory usage at the OS level using top command.







Monday, April 18, 2016

Weblogic Datasource Setup

How to create datasource for ADF application 11g/12c

  • Goto Weblogic Console
  • Select Data Sources on the Home Page
  • Click New → Generic Data Source
    • Enter the following and click Next
    • Name: AppDataSource
    • JNDI Name: jdbc/AppDS
    • Database Type: Oracle
  • Choose the JDBC driver type and click Next:
    • Database Driver: *Oracle’s Driver (Thin) for Instance Connections; Versions: Any
  • Leave the default Transcation Options and click Next :
  • Enter the database connection properties and click Next :
    • Database Name: TBD
    • Hostname: TBD
    • Port: TBD
    • Database User: apps
    • Password: TBD
    • oracle.jdbc.DRCPConnectionClass: --Blank-
  • Test the configuration and Click Next:
  • Select the Target Server: It must be targeted to the cluster or servers where the ADF app is deployed (Exclude AdminServer from the target).
  • And finish.

How to create XADatasource for SOA Suite 11g/12c

Datasource

  • Goto Weblogic Console
  • Select Data Sources on the Home Page
  • Click New → Generic Data Source
    • Enter the following and click Next
    • Name: AppDataSource
    • JNDI Name: jdbc/AppDS
    • Database Type: Oracle
  • Choose the JDBC driver type and click Next:
    • Database Driver: *Oracle’s Driver (Thin XA) for Instance Connections; Versions: Any
  • Leave the default Transcation Options and click Next :
  • Enter the database connection properties and click Next :
    • Database Name: TBD
    • Hostname: TBD
    • Port: TBD
    • Database User: apps
    • Password: TBD
    • oracle.jdbc.DRCPConnectionClass: --Blank-
  • Test the configuration and Click Next:
  • Select the Target Server: It must be targeted to the SOA cluster or SOA managed servers (Exclude AdminServer from the target).
  • And finish.
  • Remember to create JNDI name to access this datasource from DB adapter or AQ adapter .
    • This steps is only for SOA suite.

DB Adapter (Only for SOA)

  • Select Deployments on the Home Page
  • Click DbAdapter from the list
  • Select tabs Configuration > Outbound Connection Pools
  • Click on New button and select javax.resource.cci.ConnectionFactory
  • Enter JNDI Name : eis/DB/apps
    • This JNDI name should be same as the one entered in *.jca file.
  • Click on Finish 
  • Now expand the javax.resource.cci.ConnectionFactory and click on the JNDI name you just created.
  • Enter the data-source name.
    • For XA Datasources enter XADatasourceName
    • For non-xa datasources just enter DatasourceName
    • Remember to hit Enter on the keyboard as this form only registers data on keyboard enter.
  • Click on Save button
  • Go back to the Deployments page.
  • Select the DbAdapter and click on Update
  • Select Update option and click on finish
    • If its the first time, the user will be asked to create a directory path for plan file. Choose the location when asked.

AQ Adapter (Only for SOA)

  • Steps to create JNDI name for AQ adapter is same as DB adapter. It just needs repeating the above steps for AqAdapter in the deployments.


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>