I'm establishing an SSH connection through JSch on Java and everything seemed to be working fine, until I tried to run this .sh file. The shell script's name is repoUpdate.sh and it's very simple:
echo ' ****Repository update****'
echo ' Location: /home/cissys/repo/'
echo -e ' Command: svn update /home/cissys/repo/2.3.0'
svn update /home/cissys/repo/2.3.0
This is the output I get directly on the linux console with the proper response of the command:
[cissys@dsatelnx5 ~]$ repoUpdate.sh
****Repository update****
Location: /home/cissys/repo/
Command: svn update /home/cissys/repo/2.3.0
At revision 9432.
Now, here's the Java code of my method with the SSH connection that tries to call this same file
public void cmremove()
{
try
{
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, port);
UserInfo ui = new SUserInfo(pass, null);
session.setUserInfo(ui);
session.setPassword(pass);
session.connect();
ChannelExec channelExec = (ChannelExec)session.openChannel("exec");
InputStream in = channelExec.getInputStream();
channelExec.setCommand("./repoUpdate.sh");
channelExec.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
int index = 0;
while ((line = reader.readLine()) != null)
{
System.out.println(++index + " : " + line);
}
channelExec.disconnect();
session.disconnect();
System.out.println("Done!");
}
catch(Exception e)
{
System.err.println("Error: " + e);
}
}
And the response I get is the following:
run:
1 : ****Repository update****
2 : Location: /home/cissys/repo/
3 : Command: svn update /home/cissys/repo/2.3.0
Done!
BUILD SUCCESSFUL (total time: 2 seconds)
with no output or signs of execution on the svn command (At revision 9432) whatsoever.
I'm thinking it may be closing the session at some point, not letting the command execute properly. If the updateRepo.sh`` file would've had something like cp test.txt test_2.txt`, it would do it with no problem. But i only have this problem with this and some other specific .sh files.
Any help would be appreciated.