SCRIPT PARA REBOOT AUTOMATICAMENTE
reboot
Mikrotik, entrar em NEW TERMINAL e colar o script.
/system scheduler
add comment="" disabled=no interval=1d name=exec_reboot on-event=\
"/system script run reboot" policy=\
reboot,read,write,policy,test,password,sniff,sensitive start-date=\
jan/01/1970 start-time=01:00:00
/system script
add name=reboot policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive source=\
"/system reboot"
================================
---
SCRIPT PARA REBOOTAR AUTOMATICAMENTE
/system script
add name="reboot" source="/system reboot" \
policy=ftp,reboot,read,write,policy,test,winbox,password
---
AGENDAMENTO PARA REBOOT DE 15 EM 15 DIAS
/ system scheduler
add name="reboot" on-event=reboot start-date=nov/15/2006 start-time=06:05:00 \
interval=4w2d comment="REBOOT DE 15 EM 15 DIAS" disabled=no
---
================================
Limpar DNS
/system script
add name="Limpar DNS" source="/ip dns cache flush" \
policy=ftp,reboot,read,write,policy,test,winbox,password
/system scheduler
add comment="" disabled=no interval=1d name=Limpar DNS on-event=\
"/system script run Limpar DNS" policy=\
reboot,read,write,policy,test,password,sniff,sensitive start-date=\
jan/01/1970 start-time=01:00:00
================================
Ajustar o Hora e Time Zone
/system ntp client
set enabled=yes mode=unicast primary-ntp=200.160.0.8 secondary-ntp=200.192.232.8
/system clock
set time-zone-name=America/Sao_Paulo
================================
Configurando Log e Backup Automático por e-Mail Usando o Gmail
configurando o envio de emails:
no WINBOX:
menu
/tool>email>
Server: smtp.gmail.com
Port: 587
From: seu_email_no_gmail@gmail.com
User: seu_email_no_gmail@gmail.com
Password: ********** (sua senha no gmail=)
Clique no botao "Apply" e imediatamente a URL smtp.gmail.com é resolvida trocada para o IP certo.
Escrevendo um script para gerar o arquivo log-mikrotik.txt
no WINBOX
menu
/system>scripts
adicione um script chamado "salvar-log"
Name: salvar-log
Source: (código fonte)
/log print file=log-mikrotik.txt
_______________________________________
Escrevendo um script para gerar o arquivo backup-mikrotik.backup
do mesmo jeito com o seguinte código fonte:
Name: salvar-backup
Source:
/system backup save name=backup-mikrotik.backup
_______________________________________
Agora é preciso criar mais 2 scripts, um para enviar o log e outro para enviar o backup por email
Name: enviar-log
Source:
:log info message="enviando log por email"
:global data [/system clock get date]
:global hora [/system clock get time]
/tool e-mail send to="email_de_destino01@dominio.com" subject="log-mikrotik $data $hora" file=log-mikrotik.txt tls=yes
_______________________________________
Name: enviar-backup
Source:
:log info message="enviando backup por email"
:global data [/system clock get date]
:global hora [/system clock get time]
/tool e-mail send to="email_de_destino01@dominio.com" subject="backup-mikrotik $data $hora" file=backup-mikrotik.backup tls=yes
_______________________________________
/system>scheduler
agora é só agendar os 4 scripts de acordo com a necessidade, geralmente uso backup a cada 24 horas e logs a cada 6 horas como nas regras abaixo:
/system scheduler add comment="" disabled=no interval=1d name=enviar-backup-automatico \
on-event=enviar-backup policy=\
reboot,read,write,policy,test,password,sniff,sensitive start-date=\
jan/01/1970 start-time=23:10:00
/system scheduler add comment="" disabled=no interval=1d name=salvar-backup-automatico \
on-event=salvar-backup policy=\
reboot,read,write,policy,test,password,sniff,sensitive start-date=\
jan/01/1970 start-time=23:00:00
/system scheduler add comment="" disabled=no interval=6h name=salvar-log-automatico on-event=\
salvar-log policy=reboot,read,write,policy,test,password,sniff,sensitive \
start-date=jan/01/1970 start-time=00:00:00
/system scheduler add comment="" disabled=no interval=6h name=enviar-log-automatico on-event=\
enviar-log policy=reboot,read,write,policy,test,password,sniff,sensitive \
start-date=jan/01/1970 start-time=00:10:00
dhcp_android
##SCRIPT
# Limpar entradas Android
:foreach i in=[/ip dhcp-server lease find host-name~"android"] do={
:log error ("Removendo entradas android: " . [/ip dhcp-server lease get $i address]);
/ip dhcp-server lease remove $i;
}
================================================================
add comment="" disabled=no interval=1d name=Limpar DNS on-event=\
"/system script run Limpar DNS" policy=\
reboot,read,write,policy,test,password,sniff,sensitive start-date=\
jan/01/1970 start-time=01:00:00
================================
Ajustar o Hora e Time Zone
/system ntp client
set enabled=yes mode=unicast primary-ntp=200.160.0.8 secondary-ntp=200.192.232.8
/system clock
set time-zone-name=America/Sao_Paulo
================================
Configurando Log e Backup Automático por e-Mail Usando o Gmail
configurando o envio de emails:
no WINBOX:
menu
/tool>email>
Server: smtp.gmail.com
Port: 587
From: seu_email_no_gmail@gmail.com
User: seu_email_no_gmail@gmail.com
Password: ********** (sua senha no gmail=)
Clique no botao "Apply" e imediatamente a URL smtp.gmail.com é resolvida trocada para o IP certo.
Escrevendo um script para gerar o arquivo log-mikrotik.txt
no WINBOX
menu
/system>scripts
adicione um script chamado "salvar-log"
Name: salvar-log
Source: (código fonte)
/log print file=log-mikrotik.txt
_______________________________________
Escrevendo um script para gerar o arquivo backup-mikrotik.backup
do mesmo jeito com o seguinte código fonte:
Name: salvar-backup
Source:
/system backup save name=backup-mikrotik.backup
_______________________________________
Agora é preciso criar mais 2 scripts, um para enviar o log e outro para enviar o backup por email
Name: enviar-log
Source:
:log info message="enviando log por email"
:global data [/system clock get date]
:global hora [/system clock get time]
/tool e-mail send to="email_de_destino01@dominio.com" subject="log-mikrotik $data $hora" file=log-mikrotik.txt tls=yes
_______________________________________
Name: enviar-backup
Source:
:log info message="enviando backup por email"
:global data [/system clock get date]
:global hora [/system clock get time]
/tool e-mail send to="email_de_destino01@dominio.com" subject="backup-mikrotik $data $hora" file=backup-mikrotik.backup tls=yes
_______________________________________
/system>scheduler
agora é só agendar os 4 scripts de acordo com a necessidade, geralmente uso backup a cada 24 horas e logs a cada 6 horas como nas regras abaixo:
/system scheduler add comment="" disabled=no interval=1d name=enviar-backup-automatico \
on-event=enviar-backup policy=\
reboot,read,write,policy,test,password,sniff,sensitive start-date=\
jan/01/1970 start-time=23:10:00
/system scheduler add comment="" disabled=no interval=1d name=salvar-backup-automatico \
on-event=salvar-backup policy=\
reboot,read,write,policy,test,password,sniff,sensitive start-date=\
jan/01/1970 start-time=23:00:00
/system scheduler add comment="" disabled=no interval=6h name=salvar-log-automatico on-event=\
salvar-log policy=reboot,read,write,policy,test,password,sniff,sensitive \
start-date=jan/01/1970 start-time=00:00:00
/system scheduler add comment="" disabled=no interval=6h name=enviar-log-automatico on-event=\
enviar-log policy=reboot,read,write,policy,test,password,sniff,sensitive \
start-date=jan/01/1970 start-time=00:10:00
================================
Limpeza do DHCP Server Leasesdhcp_android
##SCRIPT
# Limpar entradas Android
:foreach i in=[/ip dhcp-server lease find host-name~"android"] do={
:log error ("Removendo entradas android: " . [/ip dhcp-server lease get $i address]);
/ip dhcp-server lease remove $i;
}
================================================================