Monday, September 12, 2011

ssh-keygen - password less login

To login From HostA To HostB Hostc, HostD HostE etc .... with out password.


On HOSTA (From where you connect)

$ ssh-keygen -t rsa

This will create a file
id_rsa.pub inside /home/user/.ssh

File:-  id_rsa.pub is a Public Key
File:-  id_rsa is a Private Key ( No need to copy this)



Now need to copy the id_rsa.pub(inside /home/user/.ssh/) to all hosts you want to login password less (for eg. to login to HostB,HostC,HostD,HostE etc...)

Enter password after prompting on below commands once.
$ssh-copy-id -i /scratch/aime/.ssh/id_rsa.pub oracle@hostb.us.oracle.com
$ssh-copy-id -i /scratch/aime/.ssh/id_rsa.pub oracle@hostc.us.oracle.com
$ssh-copy-id -i /scratch/aime/.ssh/id_rsa.pub oracle@hostd.us.oracle.com
$ssh-copy-id -i /scratch/aime/.ssh/id_rsa.pub oracle@hoste.us.oracle.com


Now Try:

$ ssh oracle@Hostb
Last login: Mon Sep 12 17:23:06 2011 from dhcp-singapore-test-1-vpnpool-10-191-74-134.vpn.hosta.com
[oracle@hosta ~]$

Likewise try:
$ ssh oracle@hostc

$ ssh oracle@hostd

$ ssh oracle@hoste

This will connect without password.
















Friday, September 2, 2011

For changing all .htm files in directory to .html files

sriram@ubuntu:~/scripts$ for file in *.htm; do mv "$file"  ${file%.htm}.html; done
sriram@ubuntu:~/scripts$ ls
10.html  2.html  4.html  6.html  8.html  test
1.html   3.html  5.html  7.html  9.html
sriram@ubuntu:~/scripts$

Killing all Stopped Jobs

$Jobs (Command shows 4 jobs all stopped , after I did a (Ctrl+z), Now i want to kill all that.

To List all jobs with pid's

bash-3.2$ jobs -p (will list all the pid's of jobs)

To kill those pid's
bash-3.2$kill -9 `jobs -p`








Tuesday, August 30, 2011

Exit status of Wget Validation of links inside File

while read file; do
  wget -q "$file"
  if [ $? -ne 0 ]; then
    echo "Link not up"
  else
    echo "OK"
  fi
done < url

Tuesday, August 23, 2011

VI Editor Quick Reference :


VI Editor Quick Reference :
===================

1) Comment Line from 3 to Line 5

:3,5 s/^/##/g


2) Remove ## from line 3 to Line 5

:3,5 s/##//g


3) To remove sentence from current point

Shift + d (In Escape Mode)


4) To Ignore case in VI editor:

:set ignorecase : you nearly always want this


5) Delete Line 15 till 22

:15,22d

6) Re-edit a messed-up file.

:e!

7) Undo last changes in vi editor

<esc> u or :undo

8) Setting Numbers in Line :

:set nu

9) How to redo something you undid:

:redo

10) Go to start of File :

Shift + (

11) Go to end of File :

Shift + )

12) Go to start of current Line :

0

13) Go to end of Current Line :

$





Tuesday, May 24, 2011

Check process running on particular port

3 ways to check process running on particular port :
==================================

root@ubuntu:/ubuntu# lsof -w -n -i tcp:8080
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
tnslsnr 1401 oracle   13u  IPv4  10064      0t0  TCP *:http-alt (LISTEN)

root@ubuntu:/ubuntu# fuser -n tcp 8080
8080/tcp:             1401

root@ubuntu:/ubuntu# netstat -anp|grep :8080
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      1401/tnslsnr   
root@ubuntu:/ubuntu#

Example JDBC code to check JDBC version


Please Note : Sys user wont work will throw error connect as sysdba, so created a new user srirams and checking my jdbc connection through that.


import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;

public class OracleJdbcTest {
    static String userid="srirams", password = "xxx";
    static String url = "jdbc:oracle:thin:@localhost:1521:XE";   

    static Connection con = null;
    public static void main(String[] args) throws Exception {
        Connection con = getOracleJDBCConnection();
        if(con!= null){
           System.out.println("Got Connection.");
           DatabaseMetaData meta = con.getMetaData();
           System.out.println("Driver Name : "+meta.getDriverName());
           System.out.println("Driver Version : "+meta.getDriverVersion());

        }else{
            System.out.println("Could not Get Connection");
        }
    }

    public static Connection getOracleJDBCConnection(){

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");   

        } catch(java.lang.ClassNotFoundException e) {
            System.err.print("ClassNotFoundException: ");
            System.err.println(e.getMessage());
        }

        try {
           con = DriverManager.getConnection(url, userid, password);
        } catch(SQLException ex) {
            System.err.println("SQLException: " + ex.getMessage());
        }

        return con;
    }

}

 ===================CODE Ends=================
Result:
=============================================


Got Connection.
Driver Name : Oracle JDBC driver
Driver Version : 10.1.0.2.0