Community discussions

MikroTik App
 
cicserver
Member
Member
Topic Author
Posts: 303
Joined: Sun Jul 24, 2011 12:04 pm

howto supress confirmation for reboot via script

Thu Oct 15, 2015 7:26 am

I have following script
/system reboot
OR
/system reboot;
but when i execute this script manually it asks for confirmation. how can I auto input Y so that i dont have to press key manually?
Task is to reboot mikrotik from the script ON DEMAND (from the linux ssh execution, i can successfully ssh and run the script, but it dont restart probably dueto confirmation pending)

any solution?
 
User avatar
aacable
Member
Member
Posts: 435
Joined: Wed Sep 17, 2008 11:58 am
Location: ISLAMIC Republic of PAKISTAN
Contact:

Re: howto supress confirmation for reboot via script

Thu Oct 15, 2015 9:58 am

I was in the same situation few days before (on 5.x series)
The workaround I used was following

1- Create simple script name 'reboot-mt-on-demand' with following contents
/system scheduler enable reboot-mt-on-demand
2- Create an scheduler with following command (by default it will be disabled all the time)
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=00:00:00

Now whenever you want to reboot mikrotik, you just execute command and it will reboot the router without any confirmation as you required !
/system script run reboot-mt-on-demand

This will enable the scheduler which will immediately disable the scheduler again and reboot, so that when router reboots the scheduler should be kept disabled. and if you want to execute it from linux (you should first enable the password less ssh login) use following command
ssh -q -p $PORT admin@$MIKROTIKIP /sys scheduler enable reboot-mt-on-demand
I use it to reboot remote mikrotik if required by sending SMS to my linux base system, which receives sms along with my passcode, and then ssh to mikrotik, send warning sms to admin about reboot, log event, send email, and reboot :)
I wrote about it in details at my blog.

Who is online

Users browsing this forum: No registered users and 10 guests