Grep files in Linux with Regex

Grep using Regex

grep '2018-03-20 15:55.*ERROR' wso2is-5.0.0/repository/logs/wso2carbon.log

Grep & return line number

grep -n '17:01:39,266' *.c wso2is-5.0.0/repository/logs/wso2carbon.log

RESULT- wso2carbon.log:2776828

Grep & export selected lines range

sed -n '2776828,3015070 p' wso2is-5.0.0/repository/logs/wso2carbon.log  > wso2carbon.log_ERROR_LOG

How to delete files more than 3 days old

find . -mtime +3 -print -delete

Import Certificates & JKS with WSO2 Products

First do the below change in hosts file as follows

#127.0.0.1      localhost
127.0.1.1       priyan-pc

127.0.0.1       local.wso2telco.com
#10.10.12.59    local.wso2telco.com

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
~                                                                                                                                           

"/etc/hosts" 


openssl req -x509 -nodes -days 20 -newkey rsa:2048 -keyout wso2telco.key -out wso2telco.crt

priyan@priyan-pc ~/wso2carbon/wso2telcohub-3.0.3-SNAPSHOT/repository/resources/security $ openssl req -x509 -nodes -days 20 -newkey rsa:2048 -keyout wso2telco.key -out wso2telco.crt
Generating a 2048 bit RSA private key
........................................................................+++
................................................................+++
writing new private key to 'wso2telco.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:SL    
State or Province Name (full name) [Some-State]:WESTERN
Locality Name (eg, city) []:COLOMBO
Organization Name (eg, company) [Internet Widgits Pty Ltd]:WSO2TELCO
Organizational Unit Name (eg, section) []:IT
Common Name (e.g. server FQDN or YOUR name) []:*.wso2telco.com
Email Address []:support@wso2telco.com


openssl pkcs12 -export -in wso2telco.crt -inkey wso2telco.key -name "wso2carbon" -out wso2telco.pfx
password : wso2carbon

keytool -importkeystore -srckeystore wso2telco.pfx -srcstoretype pkcs12 -destkeystore wso2carbon.jks -deststoretype JKS

keytool -export -alias wso2carbon -keystore wso2carbon.jks -file wso2telco.pem

keytool -import -alias wso2carbon -file wso2telco.pem -keystore client-truststore.jks
if alredy exsists::::::::::::[keytool error: java.lang.Exception: Certificate not imported, alias <wso2carbon> already exists]
    Solution : keytool -delete -alias wso2carbon -keystore client-truststore.jks -storepass wso2carbon

Fix springframework DispatcherServlet in Tomcat & Eclipse

How to Fix java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet in Tomcat and Eclipse

1) If you are using Maven and if spring-webmvc is not added as a dependency in your project's pom.xml then please add that.

2) The second step is to add Maven Dependency into deployment assembly. 
This is required to move all dependent JAR files into WEB-INF/lib directory of Java web application.

In order to add Maven Dependency into deployment assembly in Eclipse, follow below steps :

i) Right-click your project, select properties and choose Deployment Assembly.
ii) Now click Add and choose Java Build Path Entries and select Maven dependency theirs. 
If your project is not set for the automatic build then just refresh the project and build it.
Now you should be able to run your Spring MVC application in attached Tomcat from Eclipse IDE itself.

Copy Table with indexes

CREATE TABLE New_Table LIKE Old_Table; 
INSERT New_Table  SELECT * FROM Old_Table;

CSRF Attack WSO2ESB

ERROR
JavaLogger potential cross-site request forgery (CSRF) attack thwarted (user:<anonymous>, ip:127.0.0.1, method:POST, uri:/carbon/admin/login_action.jsp, error:required token is missing from the request)

Solution

Downgrade JDK to 1.8.0_144;
if you cannot proceed with the downgrade, so you can disable the compression in Tomcat 
repository/conf/tomcat/catalina-server.xml, 
switching compression to "off" 
instead of the default which is "on".