Mars67
November 10, 2014, 10:57am
21
Yes that is what I wanted to know thanks. I will give it a try. Still trying to learn ROS syntax.
Thank you very much Jarda.
jarda
November 10, 2014, 5:32pm
22
Glad I could point you to a better way. Post your achievements if any as they could help someone in similar situation.
mmv
December 12, 2014, 8:27pm
23
In this situation I check
[/system ntp client get last-update-before] < 3* [/system ntp client get poll-interval]
# tested on v5.4
# work with ntp package
# Resolve NTP server ip from name if time not synchronized
#
# Set ntp server names. Set to empty striing to keep untouched
:local primaryntp "ru.pool.ntp.org"
:local secondaryntp "2.ru.pool.ntp.org"
#
:if ([:len [/system package find name=ntp]] <= 0) do={
:error "NTP update script work only with ntp package"
}
/system ntp client
:if ([get status] != "synchronized") do={
:put "First NTP unsync"
:delay 60;
:if ([get status] != "synchronized") do={
:put "Second NTP unsync. Update NTP IP.";
:if ([:len $primaryntp] > 0) do={
set primary-ntp [:resolve $primaryntp]}
:if ([:len $secondaryntp] > 0) do={
set secondary-ntp [:resolve $secondaryntp]}
set enabled=no;
:delay 1;
set enabled=yes;
:log warning "NTP client IP updated."
}
}
It still dont make problems. Now work on 6.23 but i dont do deep verify.
jarda:
Unfortunatelly there is no such property like “status”:
[user@router] > /system ntp client print
enabled: yes
primary-ntp: 194.109.22.18
secondary-ntp: 216.171.120.36
mode: unicast
poll-interval: 15m
active-server: 194.109.22.18
last-update-from: 194.109.22.18
last-update-before: 4m13s310ms
last-adjustment: 4ms590us
last-bad-packet-from: 216.171.120.36
last-bad-packet-before: 17h6m33s300ms
last-bad-packet-reason: server-not-synchronizedsee manual:
http://wiki.mikrotik.com/wiki/Manual:System/Time
Maybe you can check if last-bad-packet-before has greater value than last-update-before. It means that success was more recently than fail so you can conclude you are fine with time. Also, I would check if the last-update-before is not older then some reasonable period (e.g. 24H).
gvango
May 26, 2015, 8:04am
24
Base122:
Had a requirement to set the wireless radio on a RB751U to switch on and off at certain times.
E.g. On during business hours only (07:00 - 17:00)
The simplest solution was to use the scheduler to enable and disable the radio at the required times.
However, if the router was powered off sometime during the night in this example and only switched on after the 07:00 ON time, the scheduler ON time event, would never happen and the radio would remain off.
This script checks at whatever scheduled intervals the user requires, if the radio is supposed to be ON or OFF and then sets it accordingly.
It could be adapted for example to enable and disable your 3G modem WAN link, if you only wanted the router to have an active internet connection for certain time periods for example.
# Script to ensure wireless lan radio is ON or OFF #
# between user selected times #
# The radio ON/OFF operation will not be performed if the system #
# clock is not in sync with local time, unless so required #
# Remember router is set back to default time after a reboot #
# Schedule this script at required intervals #
# Written by Peter James 2012-07-19 #
# Tested on RB751U and RouterOS v5.19 #
#####################################
## Set the Radio ON and OFF times here ##
:local RadioOnTime "07:00";
:local RadioOffTime "17:00";
# set to "no" if clock is being set manually after each reboot #
# set to "yes" if clock is being set using NTP client #
:local UseNTPClientStatus "yes";
#####################################
:log info "RadioOnOff Script Starting";
# get the name of the wlan radio interface #
:local RadioName [/interface get [find type=wlan] name];
:log info "Radio Name = $RadioName";
# First check if system clock has been syncronized with local time #
:local NTPSyncState [/system ntp client get status];
:log info "NTP Client Status = $NTPSyncState";
# Don't perform radio On or Off operation, if current real time is unknown, unless required #
:if (($NTPSyncState="synchronized") or ($UseNTPClientStatus="no")) do {
:local CurrentTime [/system clock get time];
:log info "Current Time = $CurrentTime";
# Check current ON or OFF status of radio #
:local RadioDisabled [/interface get $RadioName disabled];
:log info "Radio Disabled = $RadioDisabled";
# Where the ON time is set earlier than the OFF time #
:if ($RadioOnTime < $RadioOffTime) do {
# Radio should be ON between these times #
:if (($CurrentTime > $RadioOnTime) and ($CurrentTime < $RadioOffTime)) do {
if ($RadioDisabled=true) do {
:log info "Radio was OFF, now switching ON";
/interface enable $RadioName;
}
} else {
if ($RadioDisabled=false) do {
:log info "Radio was ON, now switching OFF";
/interface disable $RadioName;
}
}
}
# Where the ON time is set later than the OFF time #
:if ($RadioOnTime > $RadioOffTime) do {
# Radio should be OFF between these times #
:if (($CurrentTime < $RadioOnTime) and ($CurrentTime > $RadioOffTime)) do {
if ($RadioDisabled=false) do {
:log info "Radio was ON, now switching OFF";
/interface disable $RadioName;
}
} else {
if ($RadioDisabled=true) do {
:log info "Radio was OFF, now switching ON";
/interface enable $RadioName;
}
}
}
} else {
:log info "System clock may not be synchronized to local time, unable to perform operation";
}
:log info "RadioOnOff Script completed";
It works GREAT..!!!
I use it and tested RB-751G-2HnD with OS versions 5.19, 6.27 and 6.28 and it works perfectly.
Thank James for a terrific script.
I hope to also find one to do the same with an ethernet port..!!
George V.
miczx
September 8, 2015, 8:15pm
25
Hi,
I found all necessary steps here: http://mlapshin.com/index.php/2015/09/01/mikrotik-and-dads-job/
How to create scripts
Open System → Scripts window
Press Add button and the script editor window will open
Type a script name like DisableWLAN
Select policies required by the script or check all of them
Type script into the source text area: interface wireless disable wlan1
Make sure you are using the proper name of the wireless interface. It could be found in the Interfaces section.
Next you can try to test the script with “Run Script” button
Save the script with “OK” button
Create a similar EnableWLAN script.
How to schedule scripts
Open System → Scheduler window
Press Add button to open the Scheduler window
Type some meaningful name for the scheduled task like DisableWLAN
Type the name of your script into the On Event text area like DisableWLAN
Select the start date, start time (hh:mm:ss format) and the interval for repeating the action like 1d 00:00:00 (it means one day and no hours, minutes and secs)
Select required policies or check them all
Save the schedule with “OK” button
Repeat the same to schedule the enabling script
Krisken
September 9, 2015, 9:14am
26
Thought i would use this nice tutorial to keep my children off internet in the mornings
Edit
//Sonny
This works just like a charm
Is there any way to make the schema only works on weekends, Saturday and Sunday?