Community discussions

MikroTik App
 
PiGeonCZ
just joined
Topic Author
Posts: 12
Joined: Sat Jan 28, 2017 12:43 pm

ssh command exit-code always 0

Mon Nov 04, 2019 6:47 pm

Hi, I am trying to automate deployment of the let'sencrypt certificate from a windows to my Mikrotik router.
I am using posh-ssh module and its invoke-SSHcommand commandlet.
The commands are executed successfully, but the issue I am having is, that the exit-code is always 0, even if I have a typo in the command.
I could find the same exit-code in the debug log on my router, so it looks to me the router is really returning it.
Do I understand the log right?
Is this a known bug?

regards

PiGeon
SSHdebugLog.jpg
You do not have the required permissions to view the files attached to this post.
 
PiGeonCZ
just joined
Topic Author
Posts: 12
Joined: Sat Jan 28, 2017 12:43 pm

Re: ssh command exit-code always 0

Sat Dec 07, 2019 8:08 am

so am I wrong?

thanks for any comment

PiGeon
 
NicoCho
just joined
Posts: 4
Joined: Sat Mar 24, 2018 8:20 pm

Re: ssh command exit-code always 0

Mon Apr 27, 2020 12:49 am

Hi PiGeon,

I'm experiencing the same problem, trying to remotely backup other routeros devices from my routeros router.

The exit-code is always 0, whatever happens during remote script execution, and the output only gives part of the remote commands console output when executed from a local terminal.
E.g.
/system backup save
prints the following in local terminal:
Saving system configuration
Configuration backup saved
whereas the remote script returns the following:
exit-code=0;output=Configuration backup saved\n
(and the \n doesn't print well using /log info)

It might be that the 2 above messages are not ouput on the same interface (stdout vs. stderr for instance).

Whatever, I'm currently thinking of a workaround that includes making sure that all the requested scripts issue a status message to console right before leaving, such as
:put "Success" or :put "Failure: $errorMessage"
Using the last ssh-exec output line will then allow to get reasonably appropriate feedback on remote script execution.

Obviously, the script needs to handle errors so that the status message is issued in all cases (although the lack of it could be interpreted as error).

Will keep you posted on progress.

Nicolas