Good Morning,
i deploied several RB493G during last year with firmware 6.38.5, but in the last two months new units arrive with factory firmware 6.41, so i decided to restore my configuration over this version of fw.
I have a scheduler that starts a script at startup.
The strage thing is that with latest firmware the script launched by startup string crashes immediately after the instance of 1 global var.
The issue is related to the iteraction between startup string and the script, because if i start the script manually it works, even if i set the scheduler to launch another script it works…
This is the startup string:
:delay 2;
/system script run watchdog
This is the script it starts :
# watchdog_TFTP
# Set local and global vars
:local lastIpfile lastip.txt;
:local getIP 0;
:local fready 0;
:local IPconfig set.txt;
:local lastIP 0;
:global WanIP 0;
:local IPset 0;
# Reset Mac address on Wan Ether1 port (usefull when this configuration is restored on other RBs)
/interface ethernet reset-mac-address ether1;
:delay 1;
# Check IP address set on start
:set $getIP [/ip address get [find interface="ether1"] address];
:set $WanIP $getIP;
# Check if file lastipfile contains last saved ip address
# and retrieve ip address stored on it
# if file does not exist, create it and store IP address on it.
:if ([:len [/file find name=$lastIpfile]] > 0) do={
:delay 1;
:set $lastIP [/file get [/file find name=$lastIpfile] contents];
} else={
:delay 1;
};
# Check if a file with an IP address is loaded via TFTP
# retrieve new IP address e store it in the file lastipfile
# execute script autoconfig
# delete file loaded via TFTP
# if no file is loaded via TFTP stay in an endless loop and beep
# Check also if the IP is changed via remote command (getip != wanip)
:while (true) do={
:delay 1;
:set $getIP [/ip address get [find interface="ether1"] address];
:if ([:len [/file find name=$IPconfig]] > 0) do={
:delay 1;
:set $IPset [/file get [/file find name=$IPconfig] contents];
:set $WanIP $IPset;
:set $lastIP $IPset;
:set $getIP $IPset;
:set $fready 1;
/ip address set [/ip address find interface="ether1"] address=$WanIP;
/file print file=$lastIpfile;
/file set $lastIpfile contents="$IPset";
:delay 1;
/file remove $IPconfig;
:delay 1;
:execute "autoconfig";
:delay 2;
:set $IPset 0;
};
:if ($getIP != $WanIP) do= {
:set $WanIP $getIP;
:execute "autoconfig";
:set $lastIP $getIP;
/file print file=$lastIpfile;
/file set $lastIpfile contents="$lastIP";
:delay 1;
:beep frequency=2000 length=2000ms;
} else={
:if ($fready = 0) do={
:beep frequency=2000 length=200ms;
:delay 1;
};
};
};
If i look on envinronment i find only the first global var instanced, WanIp with value 0.
So it seems that after first instructions the watchdog script stops.
I remember that at the beginning, with 6.38.5 firmware, i had to use the scheduler to delay the start of watchdog script, otherwise it fault.
Is it possible that this is a problem related to the time the Os take to become fully operative ?
I’m running 6.40.5, and I can confirm that on-startup script is launched before RB has fully functional. Have a look at the log below:
jan/01/2002 02:00:01 system,info router rebooted
jan/21 15:43:08 script,info Initialising scripting
jan/21 15:43:13 interface,info e1_int link up (speed 1G, full duplex)
jan/21 15:43:13 interface,info e2_dmz link up (speed 1G, full duplex)
jan/21 15:43:13 interface,info e5_ext link up (speed 1G, full duplex)
Notice the script initialising scripting, which is executed on startup, while ethernet is not even fully up.
BTW, in environment (/system script environment), you’ll ONLY see global variables. Local variables only exist during execution, within their scope.
Good Morning, and thank you for the answer.
I have no informations about the script on my log, is there any settings to make it more verbose ?
Btw, with i added some seconds of delay at the beginning in the startup script.. and the script now works (whyyy??!!!).
It works both if i add delay in the on-startup script or in the script itself.
It seems that the first instructions cause the stop of the script.
Is the reset-mac-address a critical command to be lauched at the boot ?
This my working config at the moment.
on-startup script:
:delay 7
/system script run watchdog
# watchdog_TFTP
# ver. 26-01-2018
# Script di controllo cambio IP con supporto TFTP
# Autore: Andrea Musetti - Sitep Italia spa.
# Set local and global vars
# Use step var to check where the script exit
:local lastIpfile lastip.txt;
:local getIP 0;
:local fready 0;
:local IPconfig set.txt;
:local lastIP 0;
:global WanIP 0;
:local IPset 0;
:delay 1;
# Reset Mac address on Wan Ether1 port (usefull when this configuration is restored on other RBs)
[b]/interface ethernet reset-mac-address ether1;[/b]
:delay 1;
# Check IP address set on start
:set $getIP [/ip address get [find interface="ether1"] address];
:set $WanIP $getIP;
# Check if file lastipfile contains last saved ip address
# and retrieve ip address stored on it
# if file does not exist, create it and store IP address on it.
:if ([:len [/file find name=$lastIpfile]] > 0) do={
:delay 1;
:set $lastIP [/file get [/file find name=$lastIpfile] contents];
} else={
:delay 1;
};
# Check if a file with an IP address is loaded via TFTP
# retrieve new IP address e store it in the file lastipfile
# execute script autoconfig
# delete file loaded via TFTP
# if no file is loaded via TFTP stay in an endless loop and beep
# Check also if the IP is changed via remote command (getip != wanip)
:while (true) do={
:delay 1;
:set $getIP [/ip address get [find interface="ether1"] address];
:if ([:len [/file find name=$IPconfig]] > 0) do={
:delay 1;
:set $IPset [/file get [/file find name=$IPconfig] contents];
:set $WanIP $IPset;
:set $lastIP $IPset;
:set $getIP $IPset;
:set $fready 1;
/ip address set [/ip address find interface="ether1"] address=$WanIP;
/file print file=$lastIpfile;
/file set $lastIpfile contents="$IPset";
:delay 1;
/file remove $IPconfig;
:delay 1;
:execute "autoconfig";
:delay 2;
:set $IPset 0;
};
:if ($getIP != $WanIP) do= {
:set $WanIP $getIP;
:execute "autoconfig";
:set $lastIP $getIP;
/file print file=$lastIpfile;
/file set $lastIpfile contents="$lastIP";
:delay 1;
:beep frequency=2000 length=2000ms;
} else={
:if ($fready = 0) do={
:beep frequency=2000 length=200ms;
:delay 1;
};
};
};
Info log:
May/16/2017 17:17:32 bridge,info hardware offloading activated on bridge "bridge1" ports: ether2
May/16/2017 17:17:32 bridge,info hardware offloading activated on bridge "bridge1" ports: ether3
May/16/2017 17:17:32 bridge,info hardware offloading activated on bridge "bridge1" ports: ether4
May/16/2017 17:17:32 bridge,info hardware offloading activated on bridge "bridge1" ports: ether5
May/16/2017 17:17:33 bridge,info hardware offloading activated on bridge "bridge2" ports: ether6
May/16/2017 17:17:33 bridge,info hardware offloading activated on bridge "bridge2" ports: ether7
May/16/2017 17:17:33 bridge,info hardware offloading activated on bridge "bridge2" ports: ether8
May/16/2017 17:17:33 bridge,info hardware offloading activated on bridge "bridge2" ports: ether9
May/16/2017 17:17:36 interface,info ether2 link up (speed 1G, full duplex)
No info on script log, even if script starts or not.