Sunday, December 24, 2017

Linux crontab command

The crontab (short for "cron table") is a list of commands that are scheduled to run at regular time intervals on your computer system. The crontab command opens the crontab for editing, and lets you add, remove, or modify scheduled tasks.
The daemon which reads the crontab and executes the commands at the right time is called cron. It's named after Kronos, the Greek god of time

Command syntax

crontab [-u user] file
crontab [-u user] [-l | -r | -e] [-i] [-s]
Options
fileLoad the crontab data from the specified file. If file is a dash ("-"), the crontab data is read from standard input.
-u userSpecifies the user whose crontab is to be viewed or modified. If this option is not given, crontab opens the crontab of the user who ran crontab. Note: using su to switch users can confuse crontab, so if you are running it inside of su, always use the -u option to avoid ambiguity.
-lDisplay the current crontab.
-rRemove the current crontab.
-eEdit the current crontab, using the editor specified in the environment variable VISUALor EDITOR.
-iSame as -r, but gives the user a yes/no confirmation prompt before removing the crontab.
-sSELinux only: appends the current SELinux security context string as an MLS_LEVELsetting to the crontab file before editing or replacement occurs. See your SELinux documentation for detailed information.
Find more details here: ucrontab

Wednesday, December 20, 2017

Install Git in linux centos

Once you log in you can use the following command to install Git:
Note: you need root or sudo permission to perform this.
yum install git
You can  uninstall using the yum remove command 
yum remove git
yum clean all

Tuesday, December 12, 2017

Curl- Useful commands

Multiple Header:

Usage: curl -H “Host:localhost” -H “Content-Type:text/xml” http://www.mysite.com


Url/Param Encoding

curl -v -H 'Authorization: ESA YW40VFVmQlhyZmFlSmtCSjplejMyOXFDZTRkektOMnNp' -X GET 'http://10.40.19.8/ext/consumer/rmsj/int/1.0/item/search' -x 218.251.242.132:80 -G --data-urlencode 'itemName="'

Notice : -G --data-urlencode 'itemName="'


Http request with Proxy: (small -x)


An HTTP proxy is a proxy that the client speaks HTTP with to get the transfer done. curl will,
by default, assume that a host you point out with -x or --proxy is an HTTP proxy, and
unless you also specify a port number it will default to port 3128 (and the reason for that
particular port number is purely historical).

If you want to request the example.com web page using a proxy on 192.168.0.1 port 8080, a
command line could look like:


curl -x 192.168.0.1:8080 http:/example.com/



Request method (big -X)

The first line of the request includes the method - sometimes also referred to as "the verb".
When doing a simple GET request as this command line would do:

curl http://example.com/file

…the initial request line looks like this:

GET /file HTTP/1.1
You can tell curl to change the method into something else by using the -X or --request
command-line options followed by the actual method name. You can, for example, send a

DELETE instead of GET like this:

curl http://example.com/file -X DELETE

This command-line option only changes the text in the outgoing request, it does not change
any behavior. This is particularly important if you, for example, ask curl to send a HEAD with
-X , as HEAD is specified to send all the headers a GET response would get but never
send a response body, even if the headers otherwise imply that one would come. So, adding
-X HEAD to a command line that would otherwise do a GET will cause curl to hang, waiting
for a response body that won't come.

When asking curl to perform HTTP transfers, it will pick the correct method based on the
option so you should only very rarely have to explicitly ask for it with -X . It should also be
noted that when curl follows redirects like asked to with -L , the request method set with -
X will be sent even on the subsequent redirects.



HTTP POST ( -d or --data)

POST is the HTTP method that was invented to send data to a receiving web application,
and it is how most common HTML forms on the web works. It usually sends a chunk of
relatively small amounts of data to the receiver.

When the data is sent by a browser after data have been filled in a form, it will send it "URL
encoded", as a serialized name=value pairs separated with ampersand symbols ('&'). You
send such data with curl's -d or --data option like this:

curl -d 'name=admin&shoesize=12' http://example.com/

When specifying multiple -d options on the command line, curl will concatenate them and
insert ampersands in between, so the above example could also be made like this:

curl -d name=admin -d shoesize=12 http://example.com/

If the amount of data to send isn't really fit to put in a mere string on the command line, you
can also read it off a file name in standard curl style:

curl -d @filename http://example.com

Content-Type

POSTing with curl's  -d  option will make it include a default header that looks like Content-
Type: application/x-www-form-urlencoded . That's what your typical browser will use for a
plain POST.
Many receivers of POST data don't care about or check the Content-Type header.
If that header is not good enough for you, you should, of course, replace that and instead
provide the correct one. Such as if you POST JSON to a server and want to more accurately
tell the server about what the content is:

curl -d '{json}' -H 'Content-Type: application/json' https://example.com


Wednesday, November 29, 2017

Copying Files between Linux Computers



https://www.pks.mpg.de/~mueller/docs/suse10.2/html/opensuse-manual_en/manual/sec.filetrans.copy.html


Example using cygwin and scp :

//===The following command will copy  20171031_mule_3.4.1_1.tar file from stg-loginjpe1101z.stg.jp.local to local computer
 scp   ts-islammdsh01@stg-loginjpe1101z.stg.jp.local:/home/ts-islammdsh01/20171031_mule_3.4.1_1.tar /cygdrive/c/Projects


//==The following command will copy  2test_copy_sharif.txt file from local computer  to stg-loginjpe1101z.stg.jp.local
scp /cygdrive/c/Projects/test_copy_sharif.txt ts-islammdsh01@stg-loginjpe1101z.stg.jp.local:/home/ts-islammdsh01

Thursday, September 28, 2017

Java code coverage tool for eclipse

Overview : 

In computer science, code coverage is a measure used to describe the degree to which the source code of a program is tested by a particular test suite. A program with high code coverage has been more thoroughly tested and has a lower chance of containing software bugs than a program with low code coverage.

In this article we will see how we can generate code coverage report using tools in eclipse . There are number of tools for eclipse that we can use to generate code coverage report :


EclEmma : 
EclEmma is a free Java code coverage tool for Eclipse, available under the Eclipse Public License. It brings code coverage analysis directly into the Eclipse workbench:
  • Fast develop/test cycle: Launches from within the workbench like JUnit test runs can directly be analyzed for code coverage.
  • Rich coverage analysis: Coverage results are immediately summarized and highlighted in the Java source code editors.
  • Non-invasive: EclEmma does not require modifying your projects or performing any other setup.

How to install  EclEmma : 

There are number of ways we can install EclEmma to eclipse but in this article we will see how to install EclEmma using update site.  The steps are very easy :


use the following update site url in the ellipse install dialog
 http://update.eclemma.org/  and follow the instruction 

Help >> Install New Software 






After successfully installing the EclEmma eclipse plugin ; now it is time to see the coverage report:

Right client on project and click Coverage As > JUnit Test



Running the above command execute all the JUnit test cases and generate Code Coverage report in the coverage view: 



if you cannot see the find it from Window >> Show View >> Other..


Export the Report to local disk :

You can export the coverage report for later use: 


Click the index.html  from the exported files, your will see a coverage report like blow :


Now you can dig down you report!



Thursday, August 3, 2017

How to Read XML in Java – (DOM Parser)

In this Example I will demonstrate how to read and modify xml file using DOM parser:

Step 1. Read an xml file from disk or project directory
Step 2. Build an xml document form the xml file
Step 3. Retrive and update xml element and attribute

Course.xml file

       


<?xml version="1.0" encoding="UTF-8"?>  
<courses>     
   <course category="JAVA">  
      <title lang="en">Learn Java in 3 Months.</title>  
      <trainer>Sonoo Jaiswal</trainer>  
      <year>2008</year>  
      <fees>10000.00</fees>  
   </course> 
    <course category="XML">  
      <title lang="en">Learn XML in 2 Months.</title>  
      <trainer>Ajeet Kumar</trainer>  
      <year>2015</year>  
      <fees>4000.00</fees>  
   </course>    
</courses> 
       
 




           import java.io.File;  
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException; 

/**
 * @author Md. Shariful Islam
 
*/
public class XMLDOMTester{

 /**
  * @param args
  */
 public static void main(String[] args) {
  
  //String filepath = "c:\\Course.xml"; 
  
  File xmlFile = new File("Course.xml");
  boolean exist = xmlFile.exists();
  System.out.println(exist);
  
  
  DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
  DocumentBuilder docBuilder;
  try {
   docBuilder = docFactory.newDocumentBuilder();
   Document xmlDocument = docBuilder.parse(xmlFile);
   
   //optional, but recommended
   //read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
   xmlDocument.getDocumentElement().normalize();
   
   String rootElement =  xmlDocument.getDocumentElement().getNodeName();
   System.out.println("Root element :" +rootElement);
   
   NodeList nList = xmlDocument.getDocumentElement().getChildNodes();
   
   for (int i = 0; i < nList.getLength(); i++) {
    
    Node node = nList.item(i);
    
    if (node.getNodeType() == node.ELEMENT_NODE) {
     
     String nodeName = node.getNodeName();
     System.out.println(nodeName);
     
    }
   }
   
   
   
  } catch (ParserConfigurationException | SAXException | IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  

       
 

For modifying XML file Please read the follwing blog

how-to-modify-xml-file-in-java-dom-parser


5 Strategies for Getting More Work Done in Less Time

Summary.    You’ve got more to do than could possibly get done with your current work style. You’ve prioritized. You’ve planned. You’ve dele...