Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2008

Tip: Looking for answers? Try searching our database.

sshtools: read output from a command

Thread view: 
alcool - 07 Jan 2008 16:57 GMT
hi,
I would like to execute a command and read the output generated

// Create a instance and connect
           SshClient ssh = new SshClient();
           ssh.setSocketTimeout(30000);
           ssh.connect("192.168.1.129");
           PasswordAuthenticationClient pwd = new
PasswordAuthenticationClient();
           pwd.setUsername("root");
           pwd.setPassword("kondor");

// Execute command
           session.executeCommand("date +%Y-%m-%d");

// here I would like to read the current date on the server

thx
bye
derek - 07 Jan 2008 18:24 GMT
> hi,
> I would like to execute a command and read the output generated
[quoted text clipped - 11 lines]
> thx
> bye

A quick search on the internet showed 3 or 4 libraries with a class named SshClient in it.
What library are you using for the SshClient class? Try reading the API docs for that library first.
alcool - 09 Jan 2008 10:35 GMT
Solution found!

post the code;

SessionChannelClient session = ssh.openSessionChannel();
InputStream in = session.getInputStream();
session.executeCommand(command);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
StringBuffer buffer = new StringBuffer();
while ((line = br.readLine()) != null) {
     buffer.append(line);
}
output = buffer.toString();


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.