-1

I have to two scripts, I want to execute on a server. The problem is, that the frist script sets some environment variables and has to be executed via

. script1.ksh

while the second can be executed just by

script2.ksh

Now if I give Jsch the following String to execute

cd work_dir && . script1.ksh && ./script2.ksh

It tells me script1.ksh not found Whil if I try

cd work_dir && ./script1.ksh && ./script2.ksh

of course the variables in script2 are not defined.

Is there any way to execute such a command in JSch?

Jefe infiltrado
  • 364
  • 2
  • 15

1 Answers1

-1

The last answer in this post did the trick:

Multiple commands through Jsch Shell

    JSch jsch = new JSch();
    Session session = jsch.getSession(scpInfo.getUsername(), scpInfo.getIP(), scpInfo.getPort());
    session.setPassword(scpInfo.getPassword());
    setUpHostKey(session);
    session.connect();

    Channel channel=session.openChannel("shell");//only shell  
    channel.setOutputStream(System.out); 
    PrintStream shellStream = new PrintStream(channel.getOutputStream());  // printStream for convenience 
    channel.connect(); 
    for(String command: commands) {
        shellStream.println(command); 
        shellStream.flush();
    }

    Thread.sleep(5000);

    channel.disconnect();
    session.disconnect();

very important to sleep before the disconnection

Community
  • 1
  • 1
Jefe infiltrado
  • 364
  • 2
  • 15