Friday, February 5, 2010

Get DataObject as String

You can use below snippet to get a given DataObject as String

try {
java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
BOXMLSerializer boXml = (BOXMLSerializer) ServiceManager.INSTANCE.locateService("com/ibm/websphere/bo/BOXMLSerializer");
boXml.writeDataObject(myBO, myBO.getType().getURI(), myBO.getType().getName(), bos);
byte[] b = bos.toByteArray();
String s = new String(b);
bos.close();

}catch (java.io.IOException ioe){
ioe.printStackTrace();
}catch (Exception e ) {
e.printStackTrace();
}




Tuesday, February 2, 2010

Search multiple files using find

Search multiple files in multiple directories using find.
find /usr /opt \( -name fileName1 -o -name fileName2 \) -print

Search for fileName1, fileName2 in /usr /opt diretories.




Search and replace a foo with bar in all xml files in a specific directory

for i in `find /directory/Files -name '*.xml' `
do
echo "Changing $i file "
sed 's/foo/bar/g' $i > tmp.xml && mv tmp.txt $i
done

Transfer files accross machines using plink (putty)

Hi;

Quite often we need to download/upload files to different machines. If you have configured putty with certificates; you can use plink and cygwin gzip (to speedup the download/upload).


plink userName@PuttySession gzip -c gzip -d > fileName

Ex:

plink mruser@myServer gzip -c /var/mqm/qmgrs/SampleQmgr/errors/AMQERR01.LOG gzip -d > AMQERR01.LOG

gzip -c will compress the file and writes to stdout
gzip -d will uncompress (using pipe .. it will read from stdout as it's input).

You can also do simple cat and redirect the file...but compress the file would speed-up the transfer.