Reboot Mikrotik from OSMC on Raspberry Pi
Posted on Tue 01 November 2016 in Automatyczny dom, Raspberry Pi • 2 min read
[embedyt] http://www.youtube.com/watch?v=TmGVEop-bjk[/embedyt] Personas: 192.168.10.1 - MikroTik home router with Internet connection and WiFi LAN 192.168.10.6 - Raspberry Pi with OSMC media center OS (based on Kodi) Login to OMSC :: ssh osmc@192.168.10.6 Generate key without password: :: ssh-keygen -t dsa Transfer public key to Mikrotik router. :: scp ~/.ssh/id_dsa.pub osmc@192.168.10.1:. Login to MikroTik router: :: ssh admin@192.168.10.1 Add special group for remote users: :: /user group add name="remote_ssh" policy=ssh,reboot,!local,!telnet,!ftp,!read,!write,!policy,!test,!winbox,!password,!web,!sniff,!sensitive,!api,!romon,!dude skin=default Add new user into „remote_ssh� group: :: /user add name=osmc group=remote_ssh password=****** comment='osmc user' Import public key for „osmc� user: :: /user ssh-keys import file=id_dsa.pub user: osmc Login back into OMSC: :: ssh osmc@192.168.10.6 Create shell script called "mikrotik-osmc.sh�: :: cat << EOF > mikrotik-osmc.sh press <Enter> and paste following text: :: #!/bin/sh # script reboots Mikrotik home router xbmc-send -a "Notification(MikroTik,Rebooting router...)" ssh -l osmc -i ~/.ssh/id_dsa 192.168.10.1 "/system reboot" press <Enter>, write „EOF� (without quotes) and press <Enter> again. You will find „mikrotik-osmc.sh� file in current directory. Make this script executable: :: chmod +x mikrotik-osmc.sh You can now logout from OSMC ssh session. Following steps we will perform using OSMC GUI with keyboard or remote. I couldn’t find a way to run my script from GUI in OSMC default skin. Also couldn’t find it in Confluence skin so I decided to install Aeon Nox skin which has such feature built in. Installing Aeon Nox is easy: In OSMC GUI go to: Settings -> Add-ons choose Install from repository (v15/v16) / Get add-ons (v14) select Kodi add-on repository choose Look and feel (v16 and higher) then Skins select Aeon Nox and finally Install Now go back to Settings -> Appearance -> from Skin submenu select Aeon Nox and confirm Yes. New skin should be loaded now. Now you can add new item on the Start Screen that will allow you to reboot your router. Disclaimer: this will only work if network connection between your OSMC and your router is still working but only WAN (Internet) connection is down. From Start Screen go to System -> Skin select Settings from Home Window select Setup the Aeon Nox main menu. In left column select CUSTOM1 and in the right column select Default select action: In the following window select Custom Item and in keyboard input write: System.Exec(/home/osmc/mikrotik-osmc.sh) and press <Enter>. Go to Edit label and name it Reboot Router. Be sure that option Enabled is turned on. Go back to Start Screen and you should find new Reboot Router option. Select it and you sould see notification and after few second your MikroTik should restart. Inform all members of your family about this item. Usefull links: Execute commands with SSH on MikroTik: http://wiki.mikrotik.com/wiki/Use_SSH_to_execute_commands_(DSA_key_login) Setup Aeon Nox skin: http://kodi.wiki/view/Add-on:Aeon_Nox Full list of Kodi commands: http://kodi.wiki/view/List_of_built-in_functions