Multiple commands through JSch shell

The command is a String and can be anything the remote shell accepts. Try

cmd1 ; cmd2 ; cmd3

to run several commands in sequence. Or

cmd1 && cmd2 && cmd3

to run commands until one fails.

Even this might work:

cmd1
cmd2
cmd3

or in Java:

channel.setCommand("cmd1\ncmd2\ncmd3");

Sidenote: Don’t put passwords and user names into the code. Put them into a property file and use a system property to specify the name of the property file. That way, you can keep the file even outside the project and make sure passwords/user names don’t leak.

Leave a Comment