eworm-de / routeros-scripts

a collection of scripts for MikroTik RouterOS
GNU General Public License v3.0
1.27k stars 285 forks source link

Expect to have exponentiation and file movement capabilities. #29

Closed wy16W2pIilK1xgqN closed 1 year ago

wy16W2pIilK1xgqN commented 1 year ago

Scripts lack the ability to exponentiation operations and file moves. Hope you can achieve it.

eworm-de commented 1 year ago

What is exponentiation operations?

File move is not supported by RouterOS. Use a SCP/SFTP client...

wy16W2pIilK1xgqN commented 1 year ago

Sorry, didn't make it clear. I don't know English and use translation software to communicate with you.

The mathematical formula goes like this.

2⁴ = 16

2⁸ = 256

4⁴ = 256

This is true in linux bash.

root@archlinux:~#  echo $[2**4]
16
root@archlinux:~#  echo $[2**8]
256
root@archlinux:~#  echo $[4**4]
256
eworm-de commented 1 year ago

You can use a simple function for that:

:global Exp do={
  :if ($2 = 0) do={ :return 1; }
  :local Return 1;
  :for I from=1 to=$2 do={
    :set Return ($Return * $1);
  }
  :return $Return;
}

... store it as script mod/exp if you want to make it permanent.

To use the function:

[admin@MikroTik] > :put [ $Exp 2 4 ]
16
[admin@MikroTik] > :put [ $Exp 2 8 ]
256
[admin@MikroTik] > :put [ $Exp 4 4 ]
256

I do not have a use case for this in my scripts, so not adding.