Community discussions

MikroTik App
 
hci
Long time Member
Long time Member
Topic Author
Posts: 679
Joined: Fri May 28, 2004 5:10 pm

Schedule Reboot

Wed Mar 15, 2017 7:11 pm

Is there a easy way to schedule a reboot to occur at 3am and only happen once. This is to do a OS update.
 
novelty22
Frequent Visitor
Frequent Visitor
Posts: 64
Joined: Fri Feb 12, 2010 1:57 pm

Re: Schedule Reboot

Wed Mar 15, 2017 10:01 pm

Due to the [Y/N] prompt that RouterOS gives when trying to reboot from the command line, I had to add a "/system reboot" task to system scheduler (as disabled), then another script to enable the task, then finally schedule that script that enabled the original task.

e.g.
/system scheduler
add disabled=yes interval=1s name=reboot-mt-on-demand on-event="/system scheduler disable reboot-mt-on-demand;\r\
    \n/system reboot;" policy=reboot,read,write,policy,test,password,sniff,sensitive start-date=jan/01/1970 start-time=19:06:31
/system script
add name=reboot-mt-on-demand owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source=\
    "/system scheduler enable reboot-mt-on-demand"

Then just schedule the "reboot-mt-on-demand" script to run at 3am. Hope this makes sense
 
Genkun
newbie
Posts: 32
Joined: Mon Jul 27, 2015 11:32 am

Re: Schedule Reboot

Thu Mar 16, 2017 8:00 am

I Believe you only wish to reboot the device on days that RouterOS upgrades have been done? Do you manually do the upgrades on each device or do you have a way to do them all remotely but just need a reboot on those days?

There is a few ways you can go about this and one way is to use netwatch to trigger events remotely.

You would then set up each device with the following script. upgrade.rsc will have all the information you need to upgrade your router. If your interested in this method let me know and ill get the code together for it and send it through.
/system script
add name=rscfetch policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source={
{/file ;:if ([find name="upgrade.rsc"]!="") do={remove [find name="upgrade.rsc"]}}
:global ftpserver
:global usrnme
:global passwd
:global pckgname
:set pckgname ("upgrade.rsc")
:set ftpserver "10.10.10.1"
:set usrnme "FTPupg"
:set passwd "FTPupg123"

:if ([:len [/file find name="upgrade.rsc"]] = 0) do={
:log error "Downloading Upgrade File - $pckgname";/tool fetch address="$ftpserver" src-path="$pckgname" user="$usrnme" password="$passwd" mode=ftp;/import file=upgrade.rsc} else={
:log error "Upgrade File in Limbo";/tool e-mail send to="someone@someone.com" subject=([/system identity get name] . " RSC File Import Error")}
}

/tool netwatch add disabled=no down-script="" host=10.2.1.1 interval=1m timeout=1s up-script=rscfetch;
*This script was mostly taken from an older post and just changed with latest syntax and tweaked. But the original isn't mine. Can't remember which post it came from however.
 
LaZyLion
newbie
Posts: 32
Joined: Fri May 09, 2014 10:27 am

Re: Schedule Reboot

Tue Oct 17, 2023 11:27 pm

The following will disable itself and reboot your router at 3am.


/system scheduler add name=reboot start-time=03:00:00 on-event="{/system scheduler set [find name=reboot] disabled=yes;\n\
:execute script=\"/system reboot\";}"

re-enable as needed.
Tested on v7.11.2
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12445
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Schedule Reboot

Wed Oct 18, 2023 10:42 am

For sure everyone was waiting for your response 6 years later...

{/system scheduler set [find name=reboot] disabled=yes;
:execute script="/system reboot";}
Do you make a necropost and even write the script badly?

Who is online

Users browsing this forum: No registered users and 3 guests