We’ve got 100 Mikrotiks aprox in our network. We have some scritps running in linux servers that perform regular backups and maintenance tasks to Mikrotiks through ssh. Everything worked flawlessly till we upgraded some devices to 5.x(5.0 and 5.2).
It’s a weird issue, if I execute from a linux terminal something like:
it works, but when commands like this are in a script launched from cron, it doesn’t works. No error displayed anywhere. Mikrotik’s device log shows the connection/disconnection. If you perform any action, Eg: “/inter ether1 disable”, it is executed.
Problem only appears to me when you issue some comand to Mikrotik device through a ssh scheduled in cron. The command is executed but it’s stdout isn’t recieved. I know, it’s weird
It only occurs with 5.x. We’ve got those scripts runing for more than one year without any issue.
Observation: RouterOS is closing the SSH connection some time before it actually ends sending data. Happens only in “Single command” ssh mode, not with actual PTY allocated.
What actually happens:
ssh user@mik.ro.tik.ip '/export' |wc -c
gives around 12k less bytes it should return, also wields an error:
Write failed: Broken pipe
The export text is terminated randomly, usually in the middle of the line.
Please note that this breaks any serious mikrotik interoperability with other systems. I can provide any debugging output that would help the problem get fixed.
This is not client SSH issue (I tried openssh 5.6 to 5.8_p2, paramiko, libssh and twisted-ssh, everytime the same error).
EDIT: I’m suspecting this is purely a SMP issue.
EDIT2: confirmed, it seems like non-x86 non-SMP boxes don’t suffer from this.
Could you please try perform "/inter disable ether1 ; /inter enable ether1 " in your script. Perhaps I have same issue at http://forum.mikrotik.com/t/if-ether1-is-disable-enable-other-ether-is-too-disconnect/50686/1 When i try disable ether1 all other interface works fine, but when i enable it again all running interfaces temporarily going to down. Looks like problems with ssh is related to it. And it happening if try disable/enable only ether1.
May be a problem in the unset variable TERM.
Try to run as follows:
5 9 * * * TERM=vt100 ssh -i ~/.ssh/scripts_ro_id_dsa scripts_ro@66.78.251.41 “/ip fire man exp” > /tmp/output_cron.txt