mirror of
https://github.com/pothi/mikrotik-scripts.git
synced 2025-06-23 06:28:42 +02:00
Add test scripts and backup-buttons script
This commit is contained in:
parent
bf07a55ca5
commit
a1a0489377
6 changed files with 79 additions and 0 deletions
39
scripts/backup-buttons.rsc
Normal file
39
scripts/backup-buttons.rsc
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
# Backup button configurations - reset button, mode button.
|
||||||
|
|
||||||
|
# filename: backup-button-config
|
||||||
|
# policy: ftp, read, write, policy, test
|
||||||
|
|
||||||
|
:global adminEmail
|
||||||
|
:if ([:typeof $adminEmail] = "nothing" || $adminEmail = "") do={
|
||||||
|
:log error "adminEmail is not defined or nil."; :error "Error: Check the log"; }
|
||||||
|
|
||||||
|
:local backupName "buttons"
|
||||||
|
|
||||||
|
:local fileName "$backupName.rsc"
|
||||||
|
:local emailStatus
|
||||||
|
|
||||||
|
:log info "\nCreating a $backupName backup..."
|
||||||
|
|
||||||
|
# remove existing file, if exists for unknown reason
|
||||||
|
/file remove [find name=$fileName]; :delay 1s
|
||||||
|
|
||||||
|
# export relevant info
|
||||||
|
/system routerboard
|
||||||
|
export file=$fileName
|
||||||
|
:delay 3s
|
||||||
|
|
||||||
|
/tool e-mail
|
||||||
|
|
||||||
|
:do { send to="$adminEmail" subject="Backup of $backupName" \
|
||||||
|
body="See the subject and the attachment." file=$fileName
|
||||||
|
} on-error={ :log error "Error sending email." }
|
||||||
|
|
||||||
|
:do { :delay 5s; :set emailStatus [get last-status] } while=( $emailStatus = "in-progress" )
|
||||||
|
|
||||||
|
:if ( $emailStatus = "failed" ) do={
|
||||||
|
:log error "Backup failed!"
|
||||||
|
} else={
|
||||||
|
:log info "Backup is taken and is sent to $adminEmail."
|
||||||
|
}
|
||||||
|
|
||||||
|
/file remove $fileName
|
3
test-snippets/README.md
Normal file
3
test-snippets/README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Test Snippets
|
||||||
|
|
||||||
|
These are not full-fledged scripts. Just snippets to test a single unit of action such as detecting internet or detecting DNS. I hope someone finds it useful!
|
13
test-snippets/test-detect-internet.rsc
Normal file
13
test-snippets/test-detect-internet.rsc
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# requirement: /interface detect-internet set detect-interface-list=WAN
|
||||||
|
|
||||||
|
/interface detect-internet
|
||||||
|
# set detect-interface-list=WAN
|
||||||
|
state
|
||||||
|
|
||||||
|
:do {
|
||||||
|
:log info "Waiting for internet..."
|
||||||
|
:set $internetStatus ([:pick [print as-value] 0]->"state")
|
||||||
|
:delay 3s
|
||||||
|
} while ($internetStatus != "internet")
|
||||||
|
|
||||||
|
:log info "Connected to internet."
|
7
test-snippets/test-empty-env-var
Normal file
7
test-snippets/test-empty-env-var
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
:global adminEmail
|
||||||
|
|
||||||
|
:if ([:typeof $adminEmail] = "nothing" || $adminEmail = "") do={ :log error "Admin Email is not defined or nil."; :error "Admin Email is not defined or nil."; } else={ :put "We are good to proceed!" }
|
||||||
|
|
||||||
|
# :if ($adminEmail = "") do={ :log error "Admin Email is nil."; :error "Admin Email is nil."; }
|
||||||
|
|
||||||
|
:put "This should not be visible if admin email is not defined or nil!"
|
5
test-snippets/test-generate-password
Normal file
5
test-snippets/test-generate-password
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
:global myPassword;
|
||||||
|
|
||||||
|
:set myPassword [:pick ([/cert scep-server otp generate as-value minutes-valid=1]->"password") 0 20]
|
||||||
|
:put "Your new password is..."
|
||||||
|
:put $myPassword
|
12
test-snippets/test-log
Normal file
12
test-snippets/test-log
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# Email the generic-log when it reaches the threshold!
|
||||||
|
|
||||||
|
:global adminEmail
|
||||||
|
:local emailStatus
|
||||||
|
:local logFile "genericLog.1.txt"
|
||||||
|
:local fileContent "temp"
|
||||||
|
|
||||||
|
:do {
|
||||||
|
if ( [/file get "flash/$logFile" ] != "no such item" ) do={ :log info "Log file found!" }
|
||||||
|
} on-error={ :log warning "Log file isn't big enough!" }
|
||||||
|
|
||||||
|
:put $fileContent
|
Loading…
Add table
Add a link
Reference in a new issue