Discussions

General J2EE: how to connect to remote unix box

  1. how to connect to remote unix box (5 messages)

    I am trying to connect to remote unix boxes from java program on my dev unix box and execute some unix scripts and get the result back into text file.And i want to connect to remote box with all the credentials with in the program,uname,pwd and hostname. how to do plz help me
  2. if u r allowed to make native call then rsh is a good option. If you want to do with pure java check whether this helps or not http://jakarta.apache.org/commons/net/apidocs/org/apache/commons/net/telnet/package-tree.html
  3. Hello Biswa, Thanks for responding, Actaully i am using this code to connect import java.io.*; public class utest { static void doExec2() throws IOException { String s=null; try{ // invoke a shell and give command to it System.out.println("the second method1"); Runtime runtime = Runtime.getRuntime(); String args2 =" ssh -i ~/.ssh/monitoring.key pallavi@udev cnt_pit.sh "; //cnt_pit.sh returns count of files Process p = runtime.exec(args2); System.out.println("the second method3"); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); // read the output from the command System.out.println("Here is the standard output of the command:\n"); while ((s = stdInput.readLine()) != null) { System.out.println(s); } // read any errors from the attempted command System.out.println("Here is the standard error of the command (if any):\n"); while ((s = stdError.readLine()) != null) { System.out.println(s); } System.exit(0); } catch (IOException e) { System.out.println("exception happened - here's what I know: "); e.printStackTrace(); System.exit(-1); } catch(Exception ae){ System.out.println("Error2 "+ae);} } public static void main(String[] args) throws IOException { try{ //doExec1(); doExec2(); } catch(Exception e){System.out.println("Error3 "+e);} } } Even though i am using monitoring.key its asking me password. If i run the same commnad ssh -i ~/.ssh/monitoring.key pallavi@udev cnt_pit.sh directly i am able to get out put. Please help me. Thanks Pallavi
  4. Looks to be a shell issue. Seek help from an UNIX expert. You can try this ------------------ While the Java program is running see the parent process ID & asociated shell. if everything looks ok then check for all the environment entries available to that shell whether those are avilable to your java program or not.
  5. can u please let me know the command through which your are connecting to reote unix box..... thankful if u let me kno...

     

  6. can u please let me know the command through which your are connecting to reote unix box..... thankful if u let me kno...