0



I am using Ganymed SSH to execute commands in my Linux Machine from Java application. I have to execute 100 commands one by one.

For this in my code under for loop I am opening and closing the session for each iteration. But it is throwing some exception after 10 or 15 iterations saying that Unable to establish the connection.

I believe this is happening because the sessions are not creating frequently.

Please check the below code and guide me some good solution for achieve this.

for(String user : usersList)
{
session = connection.openSession();
session.execCommand("[ -f /home/"+user+"/.file_name] && echo \"Found\" || echo \"Not Found\"");
session.close();
}

Thanks & Regards,
Gupta Katakam

Prakash Gupta
  • 55
  • 1
  • 9

1 Answers1

1

If you try to do this, you will end up in the situation that you are in. SSH has many configuration parameter but that you need to specify in the end machine. I am not sure if you have access to the end machine or not, but in case you do not have access to the target machine, please consider adding some delay on you code after doing a disconnect and re-connect. I was also facing the same problem although I was using a different library. Let me know if this things works or not, and then we can take it forward from there.

aryann
  • 909
  • 5
  • 11
  • I tired using Thread.sleep(500); It is working for me in my local machine but I am not sure whether it will work in client system or not. That is the reason I want the solution something from framework(Ganymed) side. – Prakash Gupta Nov 21 '13 at 09:25
  • why do you say that i would not work on the client's system? it will work there also if it works on your local box. – aryann Nov 21 '13 at 09:39
  • Ok then Lets hope for the best Thank you – Prakash Gupta Nov 21 '13 at 10:21