This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes Needs to connect unix box from JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Needs to connect unix box from JAVA" Watch "Needs to connect unix box from JAVA" New topic
Author

Needs to connect unix box from JAVA

sudharsan raghav
Greenhorn

Joined: Feb 05, 2010
Posts: 6
Hi All,

I'm doing one project, where I've one requirement like this.
( Needs to connect unixbox from JAVA)

1) I've to read one particular file from Unix box(using putty) and content of that file needs to print in java console.

Please help me with this ASAP!!!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

sudharsan raghav wrote:1) I've to read one particular file from Unix box(using putty) and content of that file needs to print in java console.

You'll need an SSH library, like JSch, to connect to the UNIX machine using the SSH protocol (which is what you use PuTTY for as well).

Please help me with this ASAP!!!

Please EaseUp


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
sudharsan raghav
Greenhorn

Joined: Feb 05, 2010
Posts: 6
yes... I've completed the above mentioned task. Now I need another code where my the values of that unix file will be printed in one jsp page. That JSP page needs to refreshed for every 5 minutes which results in the execution of my java code for every 5 mins to get the latest value of the file from the unix server( Note : the file I'm taking from the unix server is a script file which runs for every 5 mins and change the values).

please help immediately!!!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

sudharsan raghav wrote:yes... I've completed the above mentioned task. Now I need another code where my the values of that unix file will be printed in one jsp page.

Well, you know how to read the file, it should then be easily to print it, shouldn't it?

That JSP page needs to refreshed for every 5 minutes which results in the execution of my java code for every 5 mins to get the latest value of the file from the unix server( Note : the file I'm taking from the unix server is a script file which runs for every 5 mins and change the values).

You'll need to do this in HTML code; either using JavaScript or the easy way using a META tag:


please help immediately!!!

I told you before to EaseUp. Once more and this thread is closed.
sudharsan raghav
Greenhorn

Joined: Feb 05, 2010
Posts: 6
Hi Rob,

I've connected unix box with this code : Using enchanter jar

import java.util.*;
public class MainSSH {

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {

SSH ssh = new DefaultSSH();
String line =null;
List ss = new ArrayList();


ssh.connect("", 22, "ddd", "");
ssh.waitFor("]$");
ssh.sendLine("cd ");
ssh.sendLine("ls omg.bmp");
ssh.sendLine("tail omg.bmp");
System.out.println(ssh.getLine());
ssh.disconnect();
}
}

With this code I can connect to the unix box but what I need to do is, I've to print the contents present in the "omg.bmp" after the tail command.. So Is there any way to print all the lines of the tail command in java. Please help me with this immediately. As I'm new to java, I'm not able to proceed with this.. Your help is really appreciated.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

I checked Enchanter briefly but it appears it cannot handle file transfers, only commands. If you want to transfer binary data simple SSH commands will not work; you will really need to use SCP (the file transfer protocol of SSH). I couldn't find anything like that in Enchanter (again, only checked briefly). Perhaps you need a different library (I again mention JSch).
sudharsan raghav
Greenhorn

Joined: Feb 05, 2010
Posts: 6
Hi Rob,

Everything is working fine.. I've one small doubt, When Executing this program via., Myeclipse I'm getting "heap space memory error". Please help me soon.

Thanks in advance.

Sudharsan.t
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

sudharsan raghav wrote:soon.

Please EaseUp.

For a reason unknown to use your Java program is using a lot of memory. The default upper limit of the JVM is about 64MB. You have two options:
1) identify what is causing the huge memory footprint and fix the issue at the source, or
2) use the -Xmx flag to specify a higher upper limit for the JVM. How you do that in your IDE I can't tell you.
sudharsan raghav
Greenhorn

Joined: Feb 05, 2010
Posts: 6
I'm using myeclipse6.5 version. please help me how to do that.


thanks,
sudharsan.t
 
GeeCON Prague 2014
 
subject: Needs to connect unix box from JAVA