aboutsummaryrefslogblamecommitdiffstats
path: root/rotate-ntp
blob: 159cdfeb7dc8e40778f9aa5aed817810fc891993 (plain) (tree)
1
2
3
4
5
6
7
8
9
                 
                             
                                                         
                                                             
                        
                                                                    
 
                
 
                     
            
 
                                                      
                                                          
 





                                                            
                                                                                
                                                              
#!rsc by RouterOS
# RouterOS script: rotate-ntp
# Copyright (c) 2013-2020 Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
#
# rotate the ntp servers
# https://git.eworm.de/cgit/routeros-scripts/about/doc/rotate-ntp.md

:global NtpPool;

:global LogPrintExit;

:local Ntp1;
:local Ntp2;

:if ([ / system ntp client get enabled ] != true) do={
  $LogPrintExit warning "NTP client is not enabled!" true;
}

:do {
  :set Ntp1 [ :resolve ("0." . $NtpPool) ];
  :set Ntp2 [ :resolve ("1." . $NtpPool) ];
} on-error={
  $LogPrintExit warning "Resolving NTP server failed." true;
}

$LogPrintExit info ("Updating NTP servers to " . $Ntp1 . " and " . $Ntp2) false;
/ system ntp client set primary-ntp=$Ntp1 secondary-ntp=$Ntp2;