Archived Forum Post

Index of archived forum posts


Monitoring SSH command process on unix server

Mar 06 '17 at 11:59

I want to send and execute commands on a unix server.

when I send the command I would like to update the user as to the status of the job. Even being able to say 'The job is still running' would be helpful. Is there a way to do this?

Accepted Answer

There are two ways to execute remote commands on a server:

  1. The rexec command (see ). This is what the SendReqExec method does. (In other words, Chilkat internallly is running the remote command in the same way as rexec.) The output of the command goes to stdout, which is sent back to the SSH client on the channel.
  2. Establish an SSH shell session and send commands on stdin (where a LF or CRLF trigger execution of the command line, just like when you're typing at a terminal) and get results on stdout. Again, the output is sent back to the SSH client on the channel.

Let's say you have a command that takes a long time, and at the very end prints "Command Completed" to stdout before it exits. In both of the above cases, after starting the remote command, your program could try to receive the stdout by calling ChannelReadAndPoll. Nothing would be received until the very end when the "Command Completed" is emitted. There's really no way to know the status of your command -- unless you bake into your command something that periodically emits the status to stdout.

The solution is to modify your command (if possible) so that it emits status output to stdout as it runs. Then your SSH client program can receive the channel output and report the status.


Thank you.