mirror of
https://github.com/pothi/mikrotik-lte-scripts.git
synced 2025-06-20 21:35:46 +02:00
Use NTP client to find internet; limit backup by time of the day; improve docs
This commit is contained in:
parent
3a233e0a3f
commit
20a1812d1f
1 changed files with 32 additions and 24 deletions
|
@ -1,44 +1,52 @@
|
|||
# Initialize the router with default values, run backup scripts and check for updates!
|
||||
|
||||
# Version: 2
|
||||
# Note: The policy of the script should match the policy of the scheduler that calls this script.
|
||||
|
||||
# changelog
|
||||
# Version: 4
|
||||
|
||||
# change log
|
||||
# version: 4
|
||||
# - date: 2025-05-31
|
||||
#. - do not execute backup scripts after 12 noon.
|
||||
# version: 3
|
||||
# - date: 2023-08-20
|
||||
# - use NTP client to test for internet.
|
||||
# - No more timeout for stable internet. Wait indefinitely until stable internet.
|
||||
# version: 2
|
||||
# - date: 2022-11-18
|
||||
# - introduction of timeout to check internet
|
||||
|
||||
:global adminEmail "noreply@example.com"
|
||||
:global adminPh 9894998949
|
||||
:global genericLogFileName "genericLog"
|
||||
:global cloudPass ""
|
||||
:global minSpeed 0
|
||||
|
||||
:global waitForDNS do={
|
||||
:local pingIP 1
|
||||
:local isUP 0
|
||||
:local timeout 5
|
||||
|
||||
:while ( $pingIP = 1 ) do={
|
||||
:do { :set $pingIP [:resolve g.co] } on-error={
|
||||
:delay 60s
|
||||
:set isUP ($isUP+1)
|
||||
:if ($isUP = $timeout) do={ :error "Internet timed out after $timeout minutes!" }
|
||||
}
|
||||
}
|
||||
:while ( ([/system/ntp/client print as-value])->"status" != "synchronized" ) do={
|
||||
:delay 60s;
|
||||
# :log info "No internet, yet."
|
||||
}
|
||||
$waitForDNS
|
||||
:log info "Init script execution has started."
|
||||
:log info "Connected to internet. Time synced."
|
||||
|
||||
# /system ntp client set enabled=yes; :delay 3s
|
||||
|
||||
:log info "Init script has started..."
|
||||
|
||||
/system script
|
||||
|
||||
:local commonScripts {"backup-cron"; "backup-scripts"; "cloud-backup"; "firmware-check-rb"; "firmware-check-ros";}
|
||||
:local commonScripts {"firmware-check-rb"; "firmware-check-ros";}
|
||||
:local initScripts ($commonScripts, "firmware-check-lte")
|
||||
|
||||
/system script
|
||||
:foreach scriptName in $initScripts do={
|
||||
:do { run $scriptName } on-error={ :log error "Error running the script $scriptName\n" }
|
||||
:delay 30s
|
||||
}
|
||||
|
||||
:log info "Init script finished execution!"
|
||||
:local currentHour [:tonum [:pick [/system clock get time] 0 2]]
|
||||
|
||||
:local backupScripts {"backup-cron"; "backup-scripts"}
|
||||
:if ($currentHour < 7) do={
|
||||
:foreach scriptName in $backupScripts do={
|
||||
:do { run $scriptName } on-error={:log error "Error running $scriptName"}
|
||||
:delay 30s
|
||||
}
|
||||
} else={
|
||||
:log info "Automated backups aren't taken after 7am."
|
||||
}
|
||||
|
||||
:log info "Init script execution is completed."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue