0

I need execute bash commands on a separate Linux machine using java on Windows.

I need run executable file from specified directory, like

cd /home/bin

How can I do this?

khris
  • 4,809
  • 21
  • 64
  • 94
  • 1
    You want to run linux commands from linux paths on Windows? – mclaassen May 26 '14 at 16:04
  • Actually I don't know how to do this, I have just linux command, linux host with credentials and I need somehow execute those commands from windows, maybe windows cmd – khris May 26 '14 at 16:06
  • 1
    Oh, on a separate machine. This is certainly possible but you will need some kind of SSH library for Windows – mclaassen May 26 '14 at 16:07
  • I use putty to run commands manually, but I do not know how to do this automatically from java – khris May 26 '14 at 16:10

2 Answers2

0

You will need to use some kind of SSH library for Java that you can then use to create an SSH connection to the target machine and run the commands inside of the SSH session.

Here is another SO question that covers this. And here is another.

Community
  • 1
  • 1
mclaassen
  • 5,018
  • 4
  • 30
  • 52
0

After long hours, I finally found useful information. please follow link "How do I run SSH commands on remote system using Java?"

Also use jar from "http://www.ganymed.ethz.ch/ssh2/" the link. It is the jar required for any person to execute ssh commands from java code in windows environment. There are other ways too. And most jars I didn't find them useful, especially when you want to automate user authentication to access linux environment.

Note, passing directly the password (ssh password) is not appropriate way of doing things.And many experts suggested in few other threads.But this simple solution works for someone who is not concerned about security.

MKod
  • 803
  • 5
  • 20
  • 33