Last active
January 19, 2023 10:10
-
-
Save iharosi/5b0b20aeb36bb5a95a18b1bafd257cf3 to your computer and use it in GitHub Desktop.
MikroTik export mailing script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 <[email protected]>" | |
:set toAddress "[email protected]" | |
################################################# | |
# 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." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script requires the following permissions: