K
K
Konstantin2017-06-15 04:25:45
linux
Konstantin, 2017-06-15 04:25:45

How to connect via SSH in Java and execute 2 commands in a row?

Good afternoon. I am writing a script to connect via ssh to the machine. The tasks are as follows:
1) Connect
2) Execute the transition to the directory and then run the script with the parameters
3) Close the connection
So. Used jsch library. There were exec and shell examples. Exec is not suitable because it executes 1 command, and Shell could do, but these commands must be entered from the keyboard. And I need these commands to be executed by the script. Can you advise how to solve this problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zooks, 2017-06-15
@small_jedi

command1 && command2

S
Saboteur, 2017-06-15
@saboteur_kiev

Option 1: execute two commands together
command1 && command2
Option 2: execute cd in the script itself
add cd at the beginning of the script

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question