Wednesday, January 18, 2012

Basic Linux Commands



*) How to extract tr.gz. file
To extract one or more members from an archive :
             tar -zxvf {file.tar.gz}

For example, If your tar name is backup.tar.gz, enter the following at a shell prompt:
             tar -zxvf backup.tar.gz



*) How to run .bin file

Change the permission of the file you downloaded to be executable. Type the following command:
              $ chmod +x file.bin

Start the installation process or run .bin file.Type the following command:
             ./file.bin

For example if .bin file name is application.bin. Type:
        $ chmod +x application.bin
        $ ./application.bin



*) How to set a BASH variable equal to the output from a command?

Use $(), which I find easier to read, and allows for nesting.
        OUTPUT=$(ls -1) echo $OUTPUT


*) How to read IP Address In a Shell Script

Type the following command:

ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'


*) How to find out particular ProcessId
                  ps -ef | grep processname
                  eg: ps -ef | grep mysql


*) How to display Line number from a file
          sed -n "linenumber p" file.txt
          sed -n "3 p" file1.txt

*) How to check Hidden file
          ls -a

*) How to check port
         netstat -tulpn


*) How to find directory on linux?
        find / -name 'httpdocs' -type d

the first parameter "/" is where to look, in this case "/" it's the entire system.
-name could be -iname to ignore case also -type is not mandatory
use : man find for more option


*) How to check free RAM size ?
                  free -m


*) How to clear cache memory ? 
        echo 1 > /proc/sys/vm/drop_caches

*) How to check linux version
              cat /proc/version

*) How to check which all service is running ?
                   intictl list 
For a particular service
                   intictl list | grep nova




Wednesday, January 4, 2012

How to Set JAVA_HOME / PATH variables Under Linux

After installing Java Development Kit on Linux/Unix, you may still need to do some configuration to get Java ready for running or compiling Java programs. The following instruction will guide you through the process of setting up JDK for software development.

In Linux, ~/.bash_profile is a startup script which generally runs once. This particular file is used for commands which run when the normal user logs in. Common uses for .bash_profile are to set environment variables such as PATH, JAVA_HOME, to create aliases for shell commands, and to set the default permissions for newly created files.

Set JAVA_HOME / PATH for single user

Login to your account and open .bash_profile file
$ cd $HOME
$ vi ~/.bash_profile

Set PATH and JAVA_HOME as follows:
 
PATH=$PATH:$HOME/bin:/usr/jdk1.6.0_30/bin
JAVA_HOME=/usr/jdk1.6.0_30


Note: Don't delete the previous PATH, Just append the jdk path after : like "/usr/jdk1.6.0_30/bin" as above .

export PATH
export JAVA_HOME

Save and close the file. Just logout and login back to see new changes:
$ echo $JAVA_HOME
$ echo $PATH


Tip: Use the following command to find out exact path to which java executable under UNIX / Linux:
$ which java


How to set JAVA PATH on Windows

Sunday, December 11, 2011

How to enable SSL on apache Tomcat 7.0

This tutorial shows how to enable SSL support for Apache Tomcat web server.
Requirement

*) Apache Tomcat 5.0
*) JDK 1.5

Note: if you have JDK below 1.4, you need to install Java Secure Socket Extensions (JSSE)

To install and configure SSL support on Tomcat, you need to follow these simple steps.


Generating the KeyStore file:

*) Create a keystore file to store the server's private key and self-signed certificate by executing the following    
    command.
*) Enter command line and change directory to your JAVA\bin folder. (Default path is: C:\Program    
    Files\Java\jre6\bin).
*) Type “keytool –genkey –alias tomcat –keyalg RSA" and press Enter.
        Where tomcat is an alias name and RSA is a key algorithm.
*) Type your password for the keystore. (Default password is: changeit). In this example, I’ll use password as “password"

Enter general information about this Certificate. The example is the image below. In the last line, Enter key password for (tomcat) should be the same as you enter before.Note that this information will be displayed to users who attempt to access a secure page.



*) The file .keystore will be created on your account. (Currently, I use administrator account so it’ll be in  
    C:\Documents and Settings\Administrator).
    I have copied the .keystore file and placed in tomcat folder.

Configure Tomcat:
*) Open server.xml in Tomcat\conf folder. (Default path is: C:\Program Files\Apache Software  
     Foundation\Tomcat x.x\conf).
*) Uncomment the paragraph below this line

<!-- Define a SSL HTTP/1.1 Connector on port 8443 This connector uses the JSSE configuration, when using APR, the connector should be using the OpenSSL style configuration described in the APR documentation -->

Add new attribute 

    keystoreFile="PATH\TO\KEYSTORE\.keystore"
    keystorePass=”password” to the Connector element. If you haven’t change keystore’s password, you    
               don’t have to add this attribute.
   Chnage protocol="org.apache.coyote.http11.Http11NioProtocol"

<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" keystoreFile="C:\software\apache-tomcat-7.0.23-windows-x64\apache-tomcat-7.0.23\.keystore" keystorePass="password" />

*) Save and restart Apache Tomcat service.

Test the result:

Open browser and navigate to the Apache Tomcat server with https://localhost:8443

Thursday, December 8, 2011

Java Date, Calendar and Time API - Tutorial


The Calendar class’ date/time API is a nifty tool for accurately manipulating date and time values without too much stress or custom coding. It provides direct support for time based objects. This article gives a few examples how this API can be used. .

The class java.util.Date was the first implementation which was used for manipulating dates. The class java.util.Calendar was added in Java 1.1 and provides simplified access to storing and manipulating dates.
It is recommended to use Calendar if possible. In reality you have to convert frequently from Date to Calendar and vice versa, e.g. during database access you often get a java.sql.Date object. The following explains how to use Calendar and how to convert Dates into Calendar.

It also offers a set of methods for converting and manipulating temporal information. In addition to retrieving the current date and time, the Calendar class also provides an API for date arithmetic. The API takes care of the numerous minor adjustments that have to be made when adding and subtracting intervals to date and time values.

Calendar’s built-in date/time arithmetic API is extremely useful. For example, consider the number of lines of code that go into calculating what the date will be five months from today. Try doing this yourself — you need to know the number of days in the current month and in the intervening months, as well as make end-of-year and leap year modifications to arrive at an accurate final result. These kinds of calculations are fairly complex and are quite easy to get wrong — especially if you’re a novice developer.


To format a date you can use the class SimpleDateFormat. For example to get today's date in the 'dd/MM/yy' format you can use:
  DateFormat df = new SimpleDateFormat("dd/MM/yy"); 
  String formattedDate = df.format(new Date());

To format the date in in the format 'yyyy/MM/dd' you can use.
  DateFormat df = new SimpleDateFormat("yyyy/MM/dd"); 
  String formattedDate = df.format(theDate);

Table 1. Calendar field access

FieldExplanationCalendar.YEAR Identifies the year
Calendar.MONTH Identifies the month
Calendar.DAY_OF_MONTH Identifies the day
Calendar.HOUR Identifies the hour
Calendar.MINUTE Identifies the minute
Calendar.SECOND Identifies the second

Tutorial is on GitHub: Timer Tutorial

Wednesday, November 23, 2011

java.lang.IllegalStateException: "Workbench has not been created yet"

I’ve been working with OSGi for quite awhile and have faced a problem "Workbench has not been createt yet" issues. I was getting this error, When i was trying to run OSGI plugin from Eclipse and I guess many of you must have face this problem. So i am writing a little bit about how to resolve this issue so others don’t repeat the same mistakes.

From a good article on eclipsezone:

java.lang.IllegalStateException: Workbench has not been created yet

This usually comes when someone tries to run a Java application against an OSGi bundle with java -classpath .... . It really means that the workbench plug-in hasn't started yet, and so calls to getWorkbench() fail. This is essentially a race condition, and can be solved by either expressing an explicit dependency on that bundle or bumping up that bundle to a higher start level than the workbench. Generally not seen, but if it is, that's what's happening.

Now to set the bundle to a higher start level than the workbench.
Select your manifest.mf, right-click, select Run As-> Run Configuration. Create a OSGi Framework launch configuration. Deselect all bundles except your bundle. Change the default set level to higher level and Press then "Add Required bundles"
Run this configuration. This should give you the correct output.

If you still get the same error ,then you can do
1. Add the -clean to the program Arguments.i,e(Run Configuration->OSGI framework->Arguments ->program Arguments)
                                           OR (Recommended 1 if failed then try 2)
2. Delete the .metadata folder which is created by default in Eclipse Workspace but before that please take the backup..:)




Hope its gonna work for you guys too..Feel free to comment.



Monday, October 31, 2011

Downloading and installing cURL on windows 7

cURL is a command-line tool. This means it is run from the command prompt (in Windows) or terminal (in Linux or OSX) and its results are displayed in the terminal window. There is no graphical interface. So in order to use cURL, you first have to open a command-line window.


To setup cURL:
  1. Download and unzip 64-bit cURL with SSL: http://curl.download.nextag.com/download/curl-7.21.7-win64-ssl-sspi.zip
  2. Copy the curl.exe file into your Windows PATH folder. By default, this is C:\Windows\System32.
  3. Download and install the Visual Studio 2010 C++ Runtime Redistributable 64 bit here: http://www.microsoft.com/download/en/details.aspx?id=13523
  4. Download the latest bundle of Certficate Authority Public Keys from http://curl.haxx.se/ca/cacert.pem
  5. Rename this file from cacert.pem to curl-ca-bundle.crt.
  6. Move this file into your Windows PATH folder. By default, this is C:\\Windows\System32.
Run cmd.exe to open your command prompt.
  1. type curl  http://www.google.com
  2. type curl  https://www.google.com
For both commands, you should see a couple pages of the HTML source code. If you see this, cURL is up and running!

Thursday, October 27, 2011

How to install Subversion,Google App Engine,Android with Eclipse.


This is tutorial assumes you already have Eclipse installed.

You can install the any plugin for Eclipse using the Software Update feature of Eclipse.
To install the plugin, using Eclipse:
Select the Help menu > Install New Software....
In the Work with text box, enter:


For Subversion:
http://subclipse.tigris.org/update_1.0.x

For Android:
https://dl-ssl.google.com/android/eclipse/

For Google App Engine:

Eclipse 3.6 (Helios):
http://dl.google.com/eclipse/plugin/3.6
Eclipse 3.5 (Galileo): http://dl.google.com/eclipse/plugin/3.5
Eclipse 3.4 (Ganymede): http://dl.google.com/eclipse/plugin/3.4
Eclipse 3.3 (Europa): http://dl.google.com/eclipse/plugin/3.3

Click OK
In the Available Software dialog, select the checkbox next to Developer Tools and click Next.
In the next window, you'll see a list of the tools to be downloaded. Click Next.
Read and accept the license agreements, then click Finish.
Note: If you get a security warning saying that the authenticity or validity of the software can't be established, click OK.
When the installation completes, restart Eclipse.

Additional Info:
Android
Subversion

How TOPT Works: Generating OTPs Without Internet Connection

Introduction Have you ever wondered how authentication apps like RSA Authenticator generate One-Time Passwords (OTPs) without requiring an i...