Community discussions

MikroTik App
 
mknnoc
Trainer
Trainer
Topic Author
Posts: 229
Joined: Thu Feb 28, 2008 6:40 am
Location: cambodia

Is it possible to have a catch of command execution?

Wed Oct 06, 2010 9:28 am

let say we execute a command "/ip firewall address-list add list=abc address=1.0.0.1" from a script.
if this execution failed, the script will :put "Failed" else :put "Success".

Is it possible to catch ?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7056
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Is it possible to have a catch of command execution?

Wed Oct 06, 2010 9:43 am

Currently there is no built in catch .

To verify if entry is added use "find" command, to search for specific entry.
 
dssmiktik
Forum Veteran
Forum Veteran
Posts: 732
Joined: Fri Aug 17, 2007 8:42 am

Re: Is it possible to have a catch of command execution?

Fri Oct 08, 2010 4:30 am

Here's a workaround that I've found for general execution:
:global RetCode;
:execute (":global RetCode;" . \
              "/ip firewall address-list add <cmd...>;" . \
              ":set RetCode 1;")

:local wait 5;
:set RetCode 0;
:while ($RetCode = 0 && $wait > 0) do={
   :set wait ($wait - 1);
   :delay 1;
}

:if ($RetCode = 1) do={
   :put "Command executed successfully"
} else={
   :if ($wait = 0) do={
      :put "Command timed out"
   } else={
      :put "Command failed"
   }
}
Once you do this a few times, you get the hang of it.
 
blake
Member
Member
Posts: 426
Joined: Mon May 31, 2010 10:46 pm
Location: Arizona

Re: Is it possible to have a catch of command execution?

Wed Dec 22, 2010 11:34 pm

Currently there is no built in catch.
Is there any timeframe on the implementation of this? Back you 2009 you mentioned this feature would be added in later releases.
 
blake
Member
Member
Posts: 426
Joined: Mon May 31, 2010 10:46 pm
Location: Arizona

Re: Is it possible to have a catch of command execution?

Wed Dec 22, 2010 11:34 pm

Currently there is no built in catch.
Is there any timeframe on the implementation of this? Back you 2009 you mentioned this feature would be added in later releases.

Who is online

Users browsing this forum: No registered users and 79 guests