Hi
Is there anyway to know whether a command on RouterOS was successful or not? Something similar to the exit status on unix. I want to do something like this in a script
if [command_successul]
then
[do_something]
else
[do_something else]
Helge
Hi
Is there anyway to know whether a command on RouterOS was successful or not? Something similar to the exit status on unix. I want to do something like this in a script
if [command_successul]
then
[do_something]
else
[do_something else]
Helge
I don’t know about all of them, but some commands do. I use:
:if ([/ping 10.0.0.2 count=1] = 1) do={
:set emessage ($emessage . “router up\n”)
} else={
:set emessage ($emessage . “router down\n”)
}
…and this works.
Thank you. This will work for commands that return 1 if success and 0 if fail. However a command like
/user add name=user1 group=group_does_not_exist
will return a context dependent error message. Any other ideas?
No, it is not a “success or fail” code for this command. In my case it returns the number of pings that were successful. If I change the count to 2, it returns 2 if both pings are successful.
The best way to tell what a command returns is
:put [/command]
With ping, it returns all the stuff for the command line, but then it adds an extra line with just the count. That is what is returned if there is no stdout (run not in a shell, but as a service).
BTW, if the command returns nothing when it works, and an error message when it doesn’t, then check the return value for a zero-length string. If not, it failed.