How to keep ssh session open


Collectors(ConsoleApp) connect to a remote server and get required text information through plink/Xojo Shell(Async). Interval is 20s (Xojo Timer).
It works well.

However, I noticed that every 20s, ssh connection is established and close.

Can I keep the ssh open while ConsoleApp is running?
I think connection/closed behavior might cause some overhead, and apparently it increases the size of server log(/var/log/secure).

Thanks in advance.

Is your Shell in the Timer Action event? If so that is the problem.

Yes, Timer based.
Can you explain the problem to me in more detail?

[quote=243946:@changwon lee]Yes, Timer based.
Can you explain the problem to me in more detail?[/quote]
“The process running in the Shell is killed when the object gets out of scope even if running in asynchronous mode (Mode = 1 or 2).”

It goes out of scope at the end of the Action event.

Instead of SSH via shell, you could get better performance with doing SSH direct.
We have a SSH2 plugin:

[quote=243946:@changwon lee]Yes, Timer based.
Can you explain the problem to me in more detail?[/quote]
Every time the Timer fires the action event it is creating a new Shell. When the Timer action completes that Shell is then destroyed. The Shell can be declared outside the Timer, but accessed within the Timer to get around this.

Shell does work with SSH connections, but as Christian says the performance is not great. I use his MBS plugin (specifically the SSH2 component) when I need to create a SSH connection.

I understand about it now.

BTW, I have went over MBS SSH2 plugin example. It connects to remote server and runs a command and display it.
For my requirement which needs to run commands by 1 min interval(repeatable) from 10 jobs, I’m not sure I can issue commands on the connected ssh session without reconnect.

How can I issue commands every 1 minutes without Timer?

David Andrews:
Do you know if I can accomplish this one with MBS?
Can you share your code about that a little bit?

You still want to use a Timer. Just don’t create the shell in it.

After getting text information from server(through ssh), I just need to pass it to Windows batch as a argument, so I think I should use Xojo shell.

If I could issue the remote command repeatably with other way instead of Timer, that would be great.
That is the part I can’t think of now.

I believe this requirement is very common for any Service application.

Actually, There is just a method to process the data and create a shell to do it with Timer, but there is no code for creating a Shell directly in Timer. Looks the same though.

My concern is not performance, it is the size of /var/log/secure.
The size of the file is getting increased because ssh connection/disconnection happens a lot.

With MBS SSH2 plugin, I checked I could keep the same ssh session for several jobs.
Trying to adjust my original code into the new plugin.

Thank you!