xbaha
March 15, 2008, 4:31pm
1
hi,
i have a simple script:
:set sw 1;
when i run from terminal, then :put $sw , i get 1
now if i chnaged it from terminal to 0, then run the script from system->script, it doesnt change!, no errors, and the run counter increases…
let me know if this is a bug, or something has changed.
thanks.
Letni
March 15, 2008, 4:51pm
2
xbaha
March 15, 2008, 5:58pm
3
the variable sw is already defined.
[admin@FL Office] > :env pr
“sw”=0
:set sw 1 doesnt run from system->script in 3.4
Letni
March 15, 2008, 6:38pm
4
You need to redefine it to access the variable from the script.
Make your script look like this.
#Links to global variable and make the variable usable in the script
:global sw
#Sets the variable sw to 1
:set sw 1
Then recheck in CLI. It works successfully for me.
-Louis
xbaha
March 15, 2008, 7:56pm
5
what if this script is running multiple times? do i still need the statment:
:global sw
in the same script?
i am defining this script at the system startup only.
Letni
March 15, 2008, 8:45pm
6
For RouterOS v3 you need to declare any variables before you use them in the script. Otherwise the script will not be aware of them.
-Louis
xbaha
March 15, 2008, 11:55pm
7
dude,
it’s not only this simple script,
for example, if i run the following code from terminal, it gets excuted:
/tool e-mail send server “XX.165.35.XX” to “myemail@domain.com ” from “ip@isp.com ” subject “ip address changed” body [/ip address get [/ip address find interface=pppoe-out1] address];
and i recieve a notification email,
now, if i put exactly the same code in system->script, and hit the excute button, the run counter increases, no errors, but i dont recieve the email!!
what is wrong here??
Letni
March 16, 2008, 1:20am
8
I just tested this on v3.4 in both CLI and script with success.
/tool e-mail send server="xx.xx.xx.xx" to="me@mydomain.com" from="me@mydomain.com" subject="ip address changed" body=[/ip address get [/ip address find interface="ether1"] address]
I would also like to add that V3.4 has several scripting quirks and yes some changed formatting and syntax. If you rely on scripting downgrade to V3.3 and wait till they fix the bugs introduced.
I would suggest posting the entire script since you seem a bit frustrated. This way we can get you a working script and review all the necessary changes to help everyone learn.
-Louis
xbaha
March 16, 2008, 10:30am
9
i have 3 script:
script1:
:global sw 1
down:
:set sw 1;
up:
:if ($sw=1) do { :set sw 0; /tool e-mail send server “2xx.165.35.xx” to “xxxx@domain.com ” from “xxxx@isp.com ” subject “ip address changed” body [/ip address get [/ip address find interface=pppoe-out1] address;] }
that’s it.
script1 will run at system startup
netwatch will monitor my gateway, if up, run script up, if down, it will run script down.
working in 2.95.
what do i need to change to make this work in 3.4??
thanks.
Letni
March 16, 2008, 5:08pm
10
After doing some testing I found that netwatch does not have access to the global variables even if you declare them at the beginning of the script.
This would appear to be a bug, you should e-mail support@mikrotik.com with your issue.
I also worked out a workaround for you until they get that fixed.
/tool netwatch add comment="Watch Gateway" disabled=no down-script=netwatch1down host=XX.XX.XX.XX interval=1m timeout=1s up-script=netwatch1up
/system script add name="netwatch1up" policy=ftp,reboot,read,write,policy,test,winbox,password,sniff source="
:global sw
:if ($sw=1) do={
:set sw 0
/tool e-mail send server="XX.XX.XX.XX" to=\"xxxx@domain.com" from="xxxx@isp.com" subject="ip address changed" body="[/ip address get [/ip address find interface="pppoe-out1"] address]"
}"
/system script add name="netwatch1down" policy=ftp,reboot,read,write,policy,test,winbox,password,sniff source="
:global sw
:set sw 1"
-Louis