Tuesday, February 19, 2013

Rename batch of files in Linux

Following awk script can be used to rename list of files.
Here, it will rename ".txt.pdf" files into ".txt" files.

for k in *.pdf; 
do mv $k `echo $k | sed 's/txt.pdf/txt/g'`; 
done

Copy files from one location to another in Linux

Following "scp" command can be used to copy files from one location to another.

scp * sujith@192.168.1.153:/apps/sujith/data

Monday, February 4, 2013

SQL concat string in informix

Suppose database contains mobile_no field which has records like "0715355403".....

If you want to remove front "0" and add "94", you can use the following SQL command.

select  "94"||mobile_no[2,10] from sms_request

This is can used in SQL where clause, too.

Thursday, January 17, 2013

Store certificate in key store

When it is using trusted certificate in JAVA, it needs to be stored in JAVA key store.

JAVA default key store is %JAVA_HOME/jre/lib/security/cacerts

Using following command you can create a specific key store.

keytool -keystore keystore_name -storepass changeit -file \export\home\root.cer -import -alias alias_name -trustcacerts

Then use the following JAVA code to use the created key store.

System.setProperty("javax.net.ssl.trustStore", "./keystore_name ");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
System.setProperty("javax.net.ssl.trustStoreType", "JKS");


Wednesday, January 16, 2013

Restart JAVA Process in crontab


Following is a shell script which can be used for restart JAVA application. If Application active count is zero(0), then this script can be used to restart the process. This shell script can be called by a crontab.

cat /dev/null > nohup.out
PRGCOU=`ps -eaf|grep JAVAApp.jar |grep -v grep |wc -l`

if [ $PRGCOU -eq 0 ]
then
nohup java -Xms32m -Xmx64m -jar JAVAApp.jar &
sleep 3
exit
fi

Tuesday, December 4, 2012

Windows Username in JAVA

This is a simple code to retrieve windows username in JAVA.

public class getWindowUsername {
    public static final void main( String args[] ) {
      String userName = System.getProperty("user.name");
      System.out.println("Window's Username: "+userName);
   }
}

Monday, December 3, 2012

List files contains 'WORD' word

In Linux, grep command can be used to find files that contain specific word.

Change directory first to location where files are located.
Use following command to get file list

grep -l WORD *.*

Above command will list all files that contains word "WORD".

To get word location in file remove -l flag.