Skip to content

Instantly share code, notes, and snippets.

@iharosi
Last active January 19, 2023 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iharosi/5b0b20aeb36bb5a95a18b1bafd257cf3 to your computer and use it in GitHub Desktop.
Save iharosi/5b0b20aeb36bb5a95a18b1bafd257cf3 to your computer and use it in GitHub Desktop.
MikroTik export mailing script
# MikroTik backup and export mailing script
# by Gergely Iharosi
# licensed with AGPL-3.0
#
# This script generates export file (including sesnitive data) and emails it to the given address.
# File name format will be the following: deviceIdentity-YYYYMMDD-HHmm.rsc
#
# Change the following two email addresses according to your needs:
:local toAddress
:local fromAddress
:set fromAddress "Sender Name <sender@address.email>"
:set toAddress "recipient@address.email"
#################################################
# Change code below this line at your own risk! #
#################################################
:local identityName
:local fileName
:local months [:toarray "jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec"]
:local currentDate
:local currentTime
:local year
:local month
:local monthString
:local day
:local hour
:local minute
:set identityName [/system identity get name]
:set currentDate [/system clock get date]
:set currentTime [/system clock get time]
:set year [:pick [:tostr $currentDate] 7 11]
:set monthString [:pick [:tostr $currentDate] 0 3]
:set day [:pick [:tostr $currentDate] 4 6]
:set hour [:pick [:tostr $currentTime] 0 2]
:set minute [:pick [:tostr $currentTime] 3 5]
:foreach k,v in=$months do={
:if ($v = $monthString) do={
if ($k < 10) do={
:local monthNumber
:set monthNumber ($k + 1)
:set month "0$monthNumber"
} else={
:set month $k
}
}
}
:set fileName "$identityName-$year$month$day-$hour$minute"
:log info "Exporting configuration..."
/export show-sensitive file=$fileName
:log info "File, $fileName.rsc has been created."
:delay 3s
/tool e-mail send to="$toAddress" subject="$identityName MikroTik config export" from="$fromAddress" file="$fileName.rsc"
:log info "File, $fileName.rsc has been emailed to $toAddress."
@iharosi
Copy link
Author

iharosi commented Mar 26, 2019

This script requires the following permissions:

  • ftp
  • read
  • policy
  • sensitive
  • write
  • test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment