Thursday, August 6, 2015

Some good Linux scripts

Change test in file

sed -i s/helloword/HELLOWORLD/g file.txt

Copy file from Linux server to Linux server

scp source_file_name username@destination_host:destination_folder
     or
scp [-r] [[user1@]hostname1:]file1 ... [[user2@]hostname2:]file2

Ex:
scp pluto:/home/jones/letter.doc .
copy the file letter.doc from the /home/jones directory of the remote system pluto to the working directory on the local system 

scp notice.doc pluto:/home/jones
copy the file notice.doc from current directory of the local system to the /home/jones directory of the remote system, pluto

Find file match name in a folder

cd <your-folder>
for f in *; do
        case $f in
                abc*.xml)
                        echo $f
                        ;;
               
def*.xml)
                        echo $f
                        ;;
        esac
done


Check file is open in linux

Check if file prefix by 'filename' is open by 'cp' process:

while :
do
    if [[ `lsof -c cp | grep filename*.xml` ]]
    then
    printf ".";
    sleep 0.5
       
    else
        break   
    fi
done
    echo "Done!"

Auto deploy script for Weblogic

Some Configuration (deploy.conf)

#Enter the package location here
source=/data/Jenkins_builds/MMT
#Enter the server IP here
FEServer=<fronend-ip-server>
BEServer=<backend-ip-server>

#Enter the target name here
FETarget=Server-0
BETarget=Server-2

#Enter package name
FEPackage=atm-ui-portlet
BEPackage=mmt-ws

#Enter the source path here
FEPath=/data/deployment/portal_destination
BEPath=/data/deployment

#Enter the portal deploy path here
PortalDeploy=/data/deployment/portal_deploy

Auto deploy script

#!/bin/bash
Logfile="logAutoDeploy.txt"

. ./deploy.conf

echo [$(date)]: ============Starting to auto deploy========== >> $Logfile

if [ -f $source/$BEPackage.war ]; then
    echo [$(date)]: ============Deploy Backend package========== >> $Logfile
    echo undeploy the package $BEPackage
    java -classpath /data/weblogic/wlserver_10.3/server/lib/weblogic.jar  weblogic.Deployer -adminurl t3://$BEServer:7001 -user <user-name> -password <password> -undeploy -name $BEPackage
    echo the package $BEPackage is undeployed >> $Logfile

    echo delete the package $BEPath/$BEPackage >> $Logfile
    cd $BEPath
    rm -rf $BEPackage

    mkdir $BEPackage
    cd $BEPackage

    echo copy $BEPackage package to $BEPath/$BEPackage >> $Logfile
    cp $source/$BEPackage.war ./
   
    echo unzip $BEPackage package >> $Logfile
    unzip $BEPackage.war
    rm -f $BEPackage.war
    echo deploy $BEPackage to back end server >> $Logfile
    java -classpath /data/weblogic/wlserver_10.3/server/lib/weblogic.jar  weblogic.Deployer -adminurl t3://$BEServer:7001 -user <user-name> -password <password> -deploy $BEPath/$BEPackage -targets $BETarget

    echo remove $BEPackage war file in Jenkins build >> $Logfile
    cd $source
    mv $BEPackage.war tmp
fi

if ls $source/$FEPackage* 1> /dev/null 2>&1; then
    echo [$(date)]: ============Deploy Frontend package========== >> $Logfile
    echo undeploy the package $FEPackage >> $Logfile
    java -classpath /data/weblogic/wlserver_10.3/server/lib/weblogic.jar  weblogic.Deployer -adminurl t3://$FEServer:7001 -user <user-name> -password <password> -undeploy -name $FEPackage
    echo the package $FEPackage is undeployed >> $Logfile

    echo delete the package $FEPackage >> $Logfile
    cd $FEPath
    rm -rf $FEPackage*

    echo copy the $FEPackage to $PortalDeploy >> $Logfile
    scp $source/$FEPackage* $PortalDeploy
    echo waiting to Liferay extracts the package >> $Logfile
    sleep 10
      
    echo deploy $FEPackage to server >> $Logfile
    java -classpath /data/weblogic/wlserver_10.3/server/lib/weblogic.jar  weblogic.Deployer -adminurl t3://$FEServer:7001 -user <user-name> -password <password> -deploy $FEPath/$FEPackage -targets $FETarget   

    echo remove $FEPackage war file in Jenkins build >> $Logfile
    cd $source
    mv $FEPackage* tmp
fi

Tuesday, June 23, 2015

Import/Export large data in Oracle DB

Export:

C:\Oracle\Database\product\11.2.0\dbhome_1\BIN>exp test/123456@db_name1 file=export_data.dump log=log.txt buffer=10485867 statistics=none tables=(table1,table2)


Import:

C:\Oracle\Database\product\11.2.0\dbhome_1\BIN>imp test/123456@db_name1 file=export_data.dump full=yes


Using Pump Export/Import

    Export:
    expdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp
    with "dmpdir" created by:
    CREATE DIRECTORY dmpdir AS '/opt/oracle';
    Import:
    impdp system/oracle DIRECTORY=dmpdir DUMPFILE=scott.dmp 
                        REMAP_SCHEMA=<OLD_SCHEMA>:<NEW_SCHEMA>

Monday, June 22, 2015

Increase heap memory in Oracle DB for data import/export

You may encounter "Out of memory" when copy Database or import/export data in SQL Developer tool, go to:

<oracle_product_domain>sqldeveloper\sqldeveloper\bin

Open file: sqldeveloper.conf, add more line:

AddVMOption -Xmx1024M

(defaullt is 128M)

Sunday, May 3, 2015

Fix bug Eclipse hangs Tomcat "starting" status nonstop when using proxy

If you have configured a proxy that does not resolves "localhost", the Tomcat startup will hang in Eclipse. To fix it, go to:

Window -> Preferences -> General -> Network Connections

and see if one of the boxes is checked. Change Active Provider to Direct (it unchecks all boxes) will resolved the problem.

References:
http://stackoverflow.com/questions/11371393/tomcat-not-starting-through-eclipse-timeout