MikroTik Script: Reset Schedule Run Count

Currently, at the time of this writing, RouterOS has no way of resetting a schedule’s run count. Though I don’t have an application for this script at the moment, I thought I’d go ahead and create a script to do this for me (to satisfy my OCD). This script will reset the run count for all schedules with a run count greater than zero by storing and recreating the schedule(s) and their values. Schedule Numbers, Names, Start Dates, Start Times, Intervals, Policies, Events, and Comments are preserved. Please, test the script in a safe environment and always create a RouterOS backup prior to running this script in a production environment.

Marthur's Reset Schedule Run Count Script v1.0

#---------------------------------------------------SCRIPT INFORMATION----------------------------------------------------
# Script:  Marthur's Reset Schedule Run Count Script
# Version: 1.0
# Updated: 12/22/2017
# Created: 12/22/2017
# Author:  Marthur Jones
# Website: https://www.marthur.com
#-----------------------------------------------TESTED USING THE FOLLOWING------------------------------------------------
# Hardware: CCR1009-7G-1C-1S+
# Firmware: v6.41
# RouterOS: v6.41
# This script will reset the run count for all schedules with a run count greater than 0 by storing and recreating the
# schedule(s) and it's values. Schedule Number, Name, Start Date, Start Time, Interval, Policy, Event, and Comments are 
# preserved.
:local scheduleNumber
:local scheduleName
:local scheduleDate
:local scheduleTime
:local scheduleInterval
:local schedulePolicy
:local scheduleOnEvent
:local scheduleComment
/system scheduler
#   Loop through schedule(s) with run counts greater than 0.
    :foreach scheduleNumber in=[find run-count > 0] do={
#   Get schedule Name value.
    :set scheduleName [get value-name=name number=$scheduleNumber]
#   Get schedule Start-Date value.
    :set scheduleDate [get value-name=start-date number=$scheduleNumber]
#   Get schedule Start-Time value.
    :set scheduleTime [get value-name=start-time number=$scheduleNumber]
#   Get schedule Interval value.
    :set scheduleInterval [get value-name=interval number=$scheduleNumber]
#   Get schedule Policy value.
    :set schedulePolicy [get value-name=policy number=$scheduleNumber]
#   Get schedule On-Event value.
    :set scheduleOnEvent [get value-name=on-event number=$scheduleNumber]
#   Get schedule Comment value.
    :set scheduleComment [get value-name=comment number=$scheduleNumber]
#   Remove schedule.
    remove $scheduleNumber
#   Add schedule.
    add name=$scheduleName start-date=$scheduleDate start-time=$scheduleTime interval=$scheduleInterval policy=$schedulePolicy on-event=$scheduleOnEvent comment=$scheduleComment

Leave a Comment

Your email address will not be published.

Scroll to Top