Page 1 of 1

Force reboot

Posted: Sun Oct 11, 2009 12:40 am
by momi
Is it possible to force reboot on RouterOS? I have some Perl scripts that do various things in RouterOS, but when it try to reboot, the command times out-because of question: Reboot, y/n. is it possible to force reboot e.g that system do not ask that question?

Re: Force reboot

Posted: Sun Oct 11, 2009 9:48 pm
by hilton
Put it in a script.
/system reboot
Tested on RB532 and RB433

Re: Force reboot

Posted: Mon Oct 12, 2009 2:27 am
by QpoX
Put it in a script.
/system reboot
Tested on RB532 and RB433
Doesn't it still need the yes or no answered?

Re: Force reboot

Posted: Mon Oct 12, 2009 10:30 am
by momi
Yes, there is a question...hm is there a way to force reboot? :?

Re: Force reboot

Posted: Mon Oct 12, 2009 10:55 am
by Chupaka
are you working via Telnet? then just send '/system reboot' + <CR><LF> + 'y'

Re: Force reboot

Posted: Mon Oct 12, 2009 12:39 pm
by momi
#!/usr/bin/perl

use Net::Telnet;#poziva se Telnet modul

#Inicijalizacija username-a i passworda
$username = 'admin';
$pass = 'password';

$telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die');
   $telnet->open('some ip'); 
   $telnet->login($username, $pass);
   $telnet->cmd('/system reboot' + <CR><LF> + 'y');

This the simple code and it returns me an error:
[root@localhost omer]# ./reboot.pl 
syntax error at ./reboot.pl line 12, near "LF>"
Execution of ./reboot.pl aborted due to compilation errors.

Re: Force reboot

Posted: Mon Oct 12, 2009 2:00 pm
by Chupaka
I'm not familiar with Perl, try
$telnet->cmd("/system reboot\ny");

Re: Force reboot

Posted: Mon Oct 12, 2009 4:15 pm
by momi
Thank you...iy didn't work. But forget perl...is there a way to force reboot in RouterOS from command line? Something like this:system force reboot.... :?

Re: Force reboot

Posted: Mon Oct 12, 2009 4:39 pm
by Chupaka
add a script with "/system reboot" command, then use "/system script run reboot" ))

Re: Force reboot

Posted: Mon Oct 12, 2009 10:39 pm
by hilton
Put it in a script.
/system reboot
Tested on RB532 and RB433
Doesn't it still need the yes or no answered?
No of course not.

This is my script.
name="reboot" owner="hilton" 
     policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive 
     run-count=0 source=
       :delay 10s
       /system reboot
It works like a bomb whether run manually or via the scheduler.

Re: Force reboot

Posted: Tue Oct 13, 2009 8:23 am
by kirshteins
I can suggest:
/system scheduler
add comment="" disabled=yes interval=1s name=schedule1 on-event=\
    "/system scheduler disable schedule1 ;\r\
    \n/system reboot;" policy=\
    reboot,read,write,policy,test,password,sniff,sensitive start-date=\
    jan/01/1970 start-time=00:00:00
This schedule will reboot the router and disable itself. You just have to enable it to reboot
/system scheduler enable schedule1

Re: Force reboot

Posted: Mon Nov 09, 2009 12:14 am
by alfareed
use
/system reboot;
Important : write ;

Re: Force reboot

Posted: Tue Apr 23, 2013 9:34 pm
by johnnydaou
Hi,

I found the good way to force reboot !!!

If you can login via telnet, and you are getting an error when rebooting, you can do this :

- Enable WatchDog and assign to it any ip.
- After a minute the routerboard will reboot.
- But you have to disable the watchdog timer immediately after reboot.

Regards,

Re: Force reboot

Posted: Fri Apr 11, 2014 8:37 am
by coylh
This command could use an improvement. I suggest:
/system reboot confirmation=no

Re: Force reboot

Posted: Mon Nov 21, 2016 11:39 pm
by WhiteBook
#!/usr/bin/perl

use strict;
use Net::Telnet; 

my $host = "192.168.88.1";
my $login = "admin";
my $passwd = "";

my $t = new Net::Telnet (Timeout => 30, Prompt => '/\] > $/' );
        $t->open( $host );
        $t->login( $login, $passwd );
        $t->cmd('
/system reboot;
y');
        $t->close();

exit

Re: Force reboot

Posted: Thu Mar 16, 2017 12:08 pm
by viktorc
I think, the best way to force reboot (until there is no support for confirmation=no switch) is to create one-time scheduler, which starts 10s after creation and calls /system reboot command (no confirmation required then):
/system scheduler add name=reboot on-event="/system reboot" start-time=([/system clock get time] + 00:00:10)
Tested on v6.34.2.

Re: Force reboot

Posted: Wed Aug 02, 2017 4:58 pm
by kalash
/system scheduler add name=REBOOT interval=5s on-event="/system scheduler remove REBOOT;/system reboot"

Re: Force reboot

Posted: Sun Jun 17, 2018 9:35 pm
by mict
try with :execute {/system reboot;}

Re: Force reboot

Posted: Wed Nov 25, 2020 11:19 am
by Intune
Hi guys.

if you need to do this via telnet...

try writing this script as two commands in notepad and then paste them both into the terminal window:


/system reboot
y

Re: Force reboot

Posted: Fri May 28, 2021 11:37 am
by sjmudd
I do agree with the original poster that having a confirmation=yes or require_confirmation=no would be useful.
Clearly workarounds have been offered but they do not solve the underlying problem or question.

Also most unix / Linux systems allow this and if you are managing the router via ssh (do people still use telnet?) if you're sending such a command you clearly want to do just that.
For interactive use it's fine to ask for confirmation and that makes sense so confirmation probably should be required by default but given Mikrotik's cli interface has quite a flexible input format I would imagine adding such a feature would be straight-forward and resolve this.

It would be nice to see such a change.

Re: Force reboot

Posted: Sat Oct 09, 2021 3:50 am
by dissident76
Use ssh commands.

After you follow this guide:
https://wiki.mikrotik.com/wiki/Use_SSH_ ... key_login)

/system ssh 127.0.0.1 command="/system reboot"
will not ask for confirmation.

Make sure:
- IP -> Services -> ssh is active
- firewall allows connections to 127.0.0.1:22
- firewall drops traffic to port 22 (ssh) coming into interfaces/from addresses not supposed to have ssh access (i.e. Internet facing, guests hostpot network, etc)

Obviously also works remotely with any IP other than 127.0.0.1; very useful for remote command/script execution.

Re: Force reboot

Posted: Sat Jan 29, 2022 8:13 am
by tangent
I can't recommend the Perl solution up-thread since telnet is horribly insecure, but this works from the command line via SSH:

$ echo '/system/reboot^My' | ssh mtrouter

Note that I embedded a literal CR in there, not a CR+LF pair. (That is, Ctrl-V Enter in Bash or Zsh, not a caret followed by an M.) The following CR is implicit in the use of "echo" rather than "echo -n".

If it doesn't work and you're still using RouterOS 6, replace the second slash in the command with a space. What I show is RouterOS 7 syntax.

Re: Force reboot

Posted: Sat Jan 29, 2022 10:39 am
by mkx
$ echo '/system/reboot^My' | ssh mtrouter


A copy-paste variant of the above:

echo -e '/system/reboot\ny' | ssh mtrouter

Re: Force reboot

Posted: Sat Jan 29, 2022 12:19 pm
by Jotne
Is it possible to force reboot on RouterOS?
This thread is missing a question.
Why?


If its due to a problem, its better to fix the problem, so reboot are not needed.
I never reboot my routers (only when upgrade).

Re: Force reboot

Posted: Sat Jan 29, 2022 12:34 pm
by pe1chl
Well, there you have the reason!
It is not necessary to always ask "why" when someone asks a simple question.
I use scheduled job like the above to reboot the router during the night after I have downloaded a new version during the day.
I always have a scheduled job like this:
/system scheduler
add name="scheduled reboot" on-event="/system reboot" policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
    start-date=nov/19/2021 start-time=03:03:03
then after I download a new version I set the start-date to the next day, and voila, update during service interval without having to stay awake.

Now about doing such things via telnet. I think it is not wise to blindly send commands over telnet. When doing such things I always use the Unix tool "expect" that allows you to chat with a remote device reading the displayed prompts and answering with the desired reply.
That also allows you to handle exceptions like timeouts or other prompts (e.g. when doing this on some other devices, before the reboot the device may prompt if you want to save unsaved configuration, and you can reply to that only in cases when this prompt actually appears).
It looks like that Perl library has some support for such things in the login() function, but not as generic as expect.

Re: Force reboot

Posted: Sat Jan 29, 2022 4:51 pm
by Jotne
If I do decide to do an upgrade, yes I can schedule a reboot, but only after I have chosen to do so. No automatic upgrade of anything.
But if OP replay that its due to a problem, he should clearly find the root cause and fix that first.

Re: Force reboot

Posted: Sat Jan 29, 2022 5:05 pm
by pe1chl
The OP never claimed that it is done to solve a problem. I think when he is using Perl scripts and wants a reboot as part of that, it may well be that it is not to solve a problem, or it may be to work around a problem that has no other workaround at the moment (e.g. some memory leak he encounters).
Or it could be part of an automatic upgrade procedure, who knows. I think it would be a great idea to have a script that does "when version is less than this, upgrade to this version" automatically when you have a large number of routers to admin and have the script do some scheduling so it does not do all your routers in a single night.

Re: Force reboot

Posted: Sat Jan 29, 2022 10:50 pm
by Jotne
The OP never claimed that it is done to solve a problem.
That is why I ask why he need to reboot, to adopt the answer to what the need is. Not guess it just for fun. :)

Re: Force reboot

Posted: Mon Jan 31, 2022 8:25 am
by Jotne
You can even remove the not needed semi column.
:execute {/system reboot}
Works on latest 7.2rc3 as well

Re: Force reboot

Posted: Sun Dec 24, 2023 11:56 am
by BalazsTM
You can even remove the not needed semi column.
:execute {/system reboot}
Works on latest 7.2rc3 as well
Thank you! Working on 7.8

Re: Force reboot

Posted: Wed May 08, 2024 1:42 am
by robmaltsystems
I like the schedule as a "outside the box" solution but the :execute {/system reboot} is perfect.

Re: Force reboot

Posted: Wed May 15, 2024 5:51 pm
by infabo
try with :execute {/system reboot;}
I came here googling for a solution to reboot without confirmation. Thanks mict!!!