zilcuanu
zilcuanu

Reputation: 3715

running ssh and executing commands on remote machines

I am a java developer and am assigned to work on a project in which I need to programmatically ssh into linux boxes and run some unix commands. After the commands have run, the output of the commands should be collected and displayed on the UI.

I saw a library called sshxcute which can be used to accomplish this. My questions are:

  1. Is there a better solution than Java based for this kind of requirements like Nodejs or Ruby on Rails
  2. Can get the real time logs from the system where the command is getting executed than getting the logs are the commands have been run.

  3. Can run multiple parallel process on the machines asynchronously.

Upvotes: 0

Views: 506

Answers (2)

PhuLuong
PhuLuong

Reputation: 537

I used jsch java library

ChannelShell channel = openShellChannel();
OutputStream outputStream = channel.getOutputStream();
PrintStream commander = new PrintStream(outputStream, true);
// Print logs
channel.setOutputStream(System.out, true);
// exec the command
commander.println(command);

Upvotes: 1

BetaRide
BetaRide

Reputation: 16884

You can use sshj. It allows you to open a ssh connection, send commands and read the output.

Upvotes: 1

Related Questions