Community discussions

MikroTik App
 
momi
newbie
Topic Author
Posts: 48
Joined: Mon Apr 06, 2009 10:31 am
Location: Sarajevo, BiH

Force reboot

Sun Oct 11, 2009 12:40 am

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?
 
User avatar
hilton
Long time Member
Long time Member
Posts: 634
Joined: Thu Sep 07, 2006 5:12 pm
Location: Jozi (aka Johannesburg), South Africa

Re: Force reboot

Sun Oct 11, 2009 9:48 pm

Put it in a script.
/system reboot
Tested on RB532 and RB433
 
QpoX
Member
Member
Posts: 385
Joined: Mon Mar 24, 2008 7:42 pm
Location: Lemvig, Denmark

Re: Force reboot

Mon Oct 12, 2009 2:27 am

Put it in a script.
/system reboot
Tested on RB532 and RB433
Doesn't it still need the yes or no answered?
 
momi
newbie
Topic Author
Posts: 48
Joined: Mon Apr 06, 2009 10:31 am
Location: Sarajevo, BiH

Re: Force reboot

Mon Oct 12, 2009 10:30 am

Yes, there is a question...hm is there a way to force reboot? :?
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Force reboot

Mon Oct 12, 2009 10:55 am

are you working via Telnet? then just send '/system reboot' + <CR><LF> + 'y'
 
momi
newbie
Topic Author
Posts: 48
Joined: Mon Apr 06, 2009 10:31 am
Location: Sarajevo, BiH

Re: Force reboot

Mon Oct 12, 2009 12:39 pm

#!/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.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Force reboot

Mon Oct 12, 2009 2:00 pm

I'm not familiar with Perl, try
$telnet->cmd("/system reboot\ny");
 
momi
newbie
Topic Author
Posts: 48
Joined: Mon Apr 06, 2009 10:31 am
Location: Sarajevo, BiH

Re: Force reboot

Mon Oct 12, 2009 4:15 pm

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.... :?
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Force reboot

Mon Oct 12, 2009 4:39 pm

add a script with "/system reboot" command, then use "/system script run reboot" ))
 
User avatar
hilton
Long time Member
Long time Member
Posts: 634
Joined: Thu Sep 07, 2006 5:12 pm
Location: Jozi (aka Johannesburg), South Africa

Re: Force reboot

Mon Oct 12, 2009 10:39 pm

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.
 
kirshteins
MikroTik Support
MikroTik Support
Posts: 592
Joined: Tue Dec 02, 2008 10:55 am

Re: Force reboot

Tue Oct 13, 2009 8:23 am

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
 
alfareed
just joined
Posts: 6
Joined: Mon Sep 28, 2009 4:37 pm

Re: Force reboot

Mon Nov 09, 2009 12:14 am

use
/system reboot;
Important : write ;
 
johnnydaou
just joined
Posts: 4
Joined: Wed Jan 23, 2013 11:13 am

Re: Force reboot

Tue Apr 23, 2013 9:34 pm

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,
 
coylh
Member Candidate
Member Candidate
Posts: 159
Joined: Tue Jul 12, 2011 12:11 am

Re: Force reboot

Fri Apr 11, 2014 8:37 am

This command could use an improvement. I suggest:
/system reboot confirmation=no
 
WhiteBook
just joined
Posts: 2
Joined: Sat Oct 29, 2016 7:37 pm

Re: Force reboot

Mon Nov 21, 2016 11:39 pm

#!/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
 
viktorc
just joined
Posts: 18
Joined: Mon Jun 05, 2006 4:00 pm

Re: Force reboot

Thu Mar 16, 2017 12:08 pm

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.
 
kalash
just joined
Posts: 1
Joined: Sat Mar 09, 2013 2:19 am

Re: Force reboot

Wed Aug 02, 2017 4:58 pm

/system scheduler add name=REBOOT interval=5s on-event="/system scheduler remove REBOOT;/system reboot"
 
mict
just joined
Posts: 4
Joined: Sun May 01, 2016 8:41 am

Re: Force reboot

Sun Jun 17, 2018 9:35 pm

try with :execute {/system reboot;}
 
Intune
just joined
Posts: 1
Joined: Wed May 13, 2020 7:28 am

Re: Force reboot

Wed Nov 25, 2020 11:19 am

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
 
sjmudd
just joined
Posts: 9
Joined: Mon Dec 03, 2018 9:19 pm

Re: Force reboot

Fri May 28, 2021 11:37 am

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.
 
User avatar
dissident76
just joined
Posts: 10
Joined: Fri Apr 10, 2015 7:33 am

Re: Force reboot

Sat Oct 09, 2021 3:50 am

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.
 
tangent
Forum Guru
Forum Guru
Posts: 1333
Joined: Thu Jul 01, 2021 3:15 pm
Contact:

Re: Force reboot

Sat Jan 29, 2022 8:13 am

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.
 
User avatar
mkx
Forum Guru
Forum Guru
Posts: 11382
Joined: Thu Mar 03, 2016 10:23 pm

Re: Force reboot

Sat Jan 29, 2022 10:39 am

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


A copy-paste variant of the above:

echo -e '/system/reboot\ny' | ssh mtrouter
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Force reboot

Sat Jan 29, 2022 12:19 pm

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).
Last edited by Jotne on Sat Jan 29, 2022 4:45 pm, edited 1 time in total.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10186
Joined: Mon Jun 08, 2015 12:09 pm

Re: Force reboot

Sat Jan 29, 2022 12:34 pm

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.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Force reboot

Sat Jan 29, 2022 4:51 pm

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.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10186
Joined: Mon Jun 08, 2015 12:09 pm

Re: Force reboot

Sat Jan 29, 2022 5:05 pm

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.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Force reboot

Sat Jan 29, 2022 10:50 pm

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. :)
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Force reboot

Mon Jan 31, 2022 8:25 am

You can even remove the not needed semi column.
:execute {/system reboot}
Works on latest 7.2rc3 as well
 
BalazsTM
just joined
Posts: 2
Joined: Sun Feb 12, 2023 11:31 pm

Re: Force reboot

Sun Dec 24, 2023 11:56 am

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

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], miks, patrikg, Victoravv and 81 guests