Search This Blog

Saturday, May 30, 2009

ssh without password

The example consists of 3 nodes , the node,tracker1 and tracker2 . The purpose of the example is to show how to setup ssh in order to login to other nodes with out a password .

Do for all
===============
mkdir ~/.ssh
chmod 755 ~/.ssh
/usr/bin/ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 644 ~/.ssh/authorized_keys
exec /usr/bin/ssh-agent $SHELL
/usr/bin/ssh-add



from node
==============
ssh hadoop@tracker2 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh hadoop@tracker1 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

scp ~/.ssh/authorized_keys hadoop@tracker2:~/.ssh/.

Tuesday, May 26, 2009

Running OS Commands and Scripts from PL/SQL Using java on Unix

This article is coming from :

http://www.dba-oracle.com/job_scheduling/commands_scripts_plsql.htm

Some extra tips are added in order to run on UNIX System. It is tested on Oracle 11g --Redhat Linux 5 el

CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
import java.io.*;
public class Host {
public static void executeCommand(String command) {
try {
String[] finalCommand;
if (isWindows()) {
finalCommand = new String[4];
finalCommand[0] = "C:\\winnt\\system32\\cmd.exe";
finalCommand[1] = "/y";
finalCommand[2] = "/c";
finalCommand[3] = command;
}
else {
finalCommand = new String[3];
finalCommand[0] = "/bin/sh";
finalCommand[1] = "-c";
finalCommand[2] = command;
}

final Process pr = Runtime.getRuntime().exec(finalCommand);
new Thread(new Runnable() {
public void run() {
try {
BufferedReader br_in = new BufferedReader(new
InputStreamReader(pr.getInputStream()));
String buff = null;
while ((buff = br_in.readLine()) != null) {
System.out.println(buff);
try {Thread.sleep(100); } catch(Exception e) {}
}
br_in.close();
}
catch (IOException ioe) {
System.out.println("Exception caught printing process output.");
ioe.printStackTrace();
}
}
}).start();

new Thread(new Runnable() {
public void run() {
try {
BufferedReader br_err = new BufferedReader(new
InputStreamReader(pr.getErrorStream()));
String buff = null;
while ((buff = br_err.readLine()) != null) {
System.out.println(buff);
try {Thread.sleep(100); } catch(Exception e) {}
}
br_err.close();
}
catch (IOException ioe) {
System.out.println("Exception caught printing process error.");
ioe.printStackTrace();
}
}
}).start();
}
catch (Exception ex) {
System.out.println(ex.getLocalizedMessage());
}
}

public static boolean isWindows() {
if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
return true;
else
return false;
}

};
/

CREATE OR REPLACE PROCEDURE host_command (p_command IN VARCHAR2)
AS LANGUAGE JAVA
NAME 'Host.executeCommand (java.lang.String)';
/

BEGIN
DBMS_JAVA.grant_permission ('RDFLDR', 'java.io.FilePermission',
'<>', 'read ,write, execute, delete');

DBMS_JAVA.grant_permission ('RDFLDR', 'SYS:java.lang.RuntimePermission',
'writeFileDescriptor', '');

DBMS_JAVA.grant_permission ('RDFLDR', 'SYS:java.lang.RuntimePermission',
'readFileDescriptor', '');
DBMS_JAVA.grant_permission( 'RDFLDR','SYS:java.io.FilePermission', '/bin/sh', 'execute' );
END;
/

SET SERVEROUTPUT ON SIZE 1000000
CALL DBMS_JAVA.SET_OUTPUT(1000000);
BEGIN
host_command (p_command => 'which java');
END;
/