MikroTik Script: Reset Script Run Count

Currently, at the time of this writing, RouterOS has no way of resetting a script’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 scripts with a run count greater than zero by storing and recreating the script(s) and their values. Script Numbers, Names, Sources, Policies, 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 Script Run Count Script v1.0

#---------------------------------------------------SCRIPT INFORMATION----------------------------------------------------
#
# Script:  Marthur's Reset Script 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 scripts with a run count greater than 0 by storing and recreating the
# script(s) and it's values. Script Number, Name, Source, Policy, and Comments are preserved.
#
#-------------------------------------------------------------------------------------------------------------------------

:local scriptNumber
:local scriptName
:local scriptSource
:local scriptPolicy
:local scriptComment

/system script

# Loop through script(s) with run counts greater than 0.
:foreach scriptNumber in=[find run-count > 0] do={

#   Get script Number value.
    :set scriptName [get value-name=name number=$scriptNumber];

#   Get script Policy value.
    :set scriptPolicy [get value-name=policy number=$scriptNumber];

#   Get script Source value.
    :set scriptSource [get value-name=source number=$scriptNumber];

#   Get script Comment value.
    :set scriptComment [get value-name=comment number=$scriptNumber];

#   Remove script.
    remove $scriptNumber

#   Add script.
    add name=$scriptName policy=$scriptPolicy source=$scriptSource comment=$scriptComment

}

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top