Community discussions

 
NikolayM
just joined
Topic Author
Posts: 5
Joined: Wed Oct 03, 2018 10:30 am

Netwatch and Scripts

Mon Nov 05, 2018 12:53 pm

Good afternoon, there is a Mikrotik RB750G r2 with the firmware version 6.43.4, there was a version 6.32 earlier and on this version scripts were written.
At present on a new firmware a problem with start of scripts by means of Netwatch which need more permissions than read, write,test,reboot,namely "policy" to have access to global variables, installation of a tick "don't Request Permission" does not help. I tried to solve the problem using an intermediate script, but also failed. Tell me how to solve the problem. The example script is simple and for test purposes.
The value of a global variable:
 system scrip environment print
 
 # NAME               VALUE                                                      
3 IspReserveIF       RT-INET-Reserve
The Configuration Of The Netwatch:
/tool netwatch
add host=8.8.8.8 up-script="/system script run script1"
The content of the script:
:global IspReserveIF
/log warning $IspReserveIF
 
vasilaos
Frequent Visitor
Frequent Visitor
Posts: 91
Joined: Tue Aug 04, 2009 9:50 am

Re: Netwatch and Scripts

Mon Nov 05, 2018 7:50 pm

I had this problem after i upgraded to some newer version. Netwatch scripts and all subscripts are run from system user and not from admin user. When you run the script manually you create the global variable from the admin user wich is loged in at the moment but the variable is not visible for the system user. So is not a problem of premission but of variable scope that is avalible only from the user that created it. So global is not really a global variable or global only for the user environment that created it. You must clear the global variable and let the script that runs from netwatch to create it for you
 
NikolayM
just joined
Topic Author
Posts: 5
Joined: Wed Oct 03, 2018 10:30 am

Re: Netwatch and Scripts

Tue Nov 06, 2018 8:42 am

I set all scripts that use global variables to "don't Request Permission". Rebooted the router, but it did not help. I started to analyze further and found out that scripts run through Netwatch in principle do not create global variables. Variables I have created by running scripts using Scheduler.
 
NikolayM
just joined
Topic Author
Posts: 5
Joined: Wed Oct 03, 2018 10:30 am

Re: Netwatch and Scripts  [SOLVED]

Wed Nov 07, 2018 2:10 pm

I found a solution to my problem of running scripts that require more permissions than read, write, reboot, test. I transferred the responsibility for running scripts to Scheduler, but the initiator of the launch is Netwatch. The scheduler that runs the required script is in the "disable" state, and Netwatch puts It in the "enabled"state. But before you do this, you must set the scheduler to the current date and time 10 seconds ahead. Time delay start choose to your taste, it depends on the speed of the scripts and that it was not less than the interval between the calculation of the start time and enable scheduler. In my example, is considered a transition if the value is 59 seconds, 59 minutes and 23 hours. for example ,if now 10:10:50, and we need to run the script after 30 seconds, then the start time will be 10:11:20. This will not work with the date when switching to a new day, it does not matter to me, because at night I do not care about the speed of operation, and the script will work at the interval specified in the scheduler. Then, when the last script is executed, the scheduler will go back to the disable state.
The Configuration Of The Netwatch
/system script run DeltaTime
/system scheduler enable CHECK-INET-ALARM
Script DeltaTime
#Time separator character
:local Mysymbol ":";
#Time change (maximum 23 hours 59 minutes 59 seconds). If you want to subtract, make the value of the variable negative
:local deltaH 0;
:local deltaM 0;
:local deltaS 10;
#Time two characters and add a change to them
:local MyTime1 ([:pick [/system clock get time] 0 2]+$deltaH);
:local MyTime2 ([:pick [/system clock get time] 3 5]+$deltaM);
:local MyTime3 ([:pick [/system clock get time] 6 8]+$deltaS);
:local MyDate (:pick [/system clock get date] );
#Condition
:if ($MyTime3>="60")  do={ :set MyTime3 ($MyTime3 - 60); :set MyTime2 ($MyTime2 + 1);} else={:if ($MyTime3<"0") do={ :set MyTime3 ($MyTime3 + 60); :set MyTime2 ($MyTime2 + 1);}};
:if ($MyTime2>="60")  do={ :set MyTime2 ($MyTime2 - 60); :set MyTime1 ($MyTime1 + 1);} else={:if ($MyTime2<"0") do={ :set MyTime2 ($MyTime2 + 60); :set MyTime1 ($MyTime1 - 1);}};
:if ($MyTime1>="24")  do={ :set MyTime1 ($MyTime1 - 24)} else={:if ($MyTime1<"0") do={ :set MyTime1 ($MyTime1 + 24)}};

#Get the current time plus $delta
:local DeltaPlus  [:totime ($MyTime1.$Mysymbol.$MyTime2.$Mysymbol.$MyTime3)];
#Log for debugging
#:log info $MyTime1;
#:log info $MyTime2;
#:log info $MyTime3;
#:log info $DeltaPlus;
#:log info $MyDate;
#Changing the scheduler settings
/system scheduler set start-time=$DeltaPlus start-date=$MyDate CHECK-INET-ALARM
/system scheduler set start-time=$DeltaPlus start-date=$MyDate CHECK-LOCAL-ALARM
The Configuration Of The Sheduler
/system script run CHECK-INET-ALARM
/system script run CHECK-LOCAL-ALARM
In the last script there is a line that turns off the scheduler
/system scheduler disable CHECK-INET-ALARM

Who is online

Users browsing this forum: No registered users and 124 guests