python script for remote boot up/reboot/shutdown
#1
i am not a programmer. i have a suggestion for a python script for anyone who think they could/want to do it.

in my case i have my movies pictures and music on a server to stream things to xbmc. a server that is in a place far from the tv where xbmc is. sometimes i need to reboot or turn on this server.
i believe a python script doing this from within xbmc would be great. i tried google to find example scripts but didn't get far so anyone up for the challenge try it and share it it worx. Smile

/floink
Reply
#2
wouldnt a wake on lan work to turn the server on. then all you would need todo is try and access your movies, the server would turn o, 5 mins later your movies would be available.
Reply
#3
i've tried that and my filserver doesn't seem to care... but still reboot and shutdown would be useful i think.
Reply
#4
rebooting would be easy enough if you dont mind running a small script on your pc. starting up the pc using wake on lan would be more difficult
+-------------------------------------------------------------------------------+
| xbox1: v1.1, samsung dvd,120 gb hd,x-ecuter pro 2.2,xbmc
| xbox2: v1.2, phillips dvd, retail hd, tsop, avalaunch, xbmc
| xirremote, x2_4977, media center utils
Reply
#5
oh i don't mind that if it brings me the functionality i want and don't affect the fileserver performance.
is it similar to what is talked about in this thread?
edit**
ok so i found the example script they're talking about here but i have no clue of what to do with it:
Quote:# rebootserver.py - reboots a remove server
import win32security
import win32api
import sys
import time
from ntsecuritycon import *

def adjustprivilege(priv, enable = 1):
   # get the process token.
   flags = token_adjust_privileges | token_query
   htoken = win32security.openprocesstoken(win32api.getcurrentprocess(), flags)
   # get the id for the system shutdown privilege.
   id = win32security.lookupprivilegevalue(none, priv)
   # now obtain the privilege for this process.
   # create a list of the privileges to be added.
   if enable:
       newprivileges = [(id, se_privilege_enabled)]
   else:
       newprivileges = [(id, 0)]
   # and make the adjustment.
   win32security.adjusttokenprivileges(htoken, 0, newprivileges)

def rebootserver(message="server rebooting", timeout=30, bforce=0, breboot=1):
   adjustprivilege(se_shutdown_name)
   try:
       win32api.initiatesystemshutdown(none, message, timeout, bforce, breboot)
   finally:
       # now we remove the privilege we just added.
       adjustprivilege(se_shutdown_name, 0)

def abortreboot():
   adjustprivilege(se_shutdown_name)
   try:
       win32api.abortsystemshutdown(none)
   finally:
       # now we remove the privilege we just added.
       adjustprivilege(se_shutdown_name, 0)
           
if =='':
       message = "this server is pretending to reboot\r\n"
       message = message + "the shutdown will stop in 10 seconds"
       rebootserver(message)
       print "sleeping for 10 seconds"
       time.sleep(10)
       print "aborting shutdown"
       abortreboot()
/floink
Reply
#6
for wake on lan you could try the next script (didn't test it on my pc)
Quote:import xbmc, xbmcgui
import struct, socket

def wakeonlan(ethernet_address):

 # construct a six-byte hardware address

 addr_byte = ethernet_address.split(':')
 hw_addr = struct.pack('bbbbbb', int(addr_byte[0], 16),
   int(addr_byte[1], 16),
   int(addr_byte[2], 16),
   int(addr_byte[3], 16),
   int(addr_byte[4], 16),
   int(addr_byte[5], 16))

 # build the wake-on-lan "magic packet"...

 msg = '\xff' * 6 + hw_addr * 16

 # ...and send it to the broadcast address using udp

 s = socket.socket(socket.af_inet, socket.sock_dgram)
 s.setsockopt(socket.sol_socket, socket.so_broadcast, 1)
 s.sendto(msg, ('<broadcast>', 7))
 s.close()

# example use
wakeonlan('00:03:34:53:6c:7a')

as for the example script,

instead of
Quote:if =='':
      message = "this server is pretending to reboot\r\n"
      message = message + "the shutdown will stop in 10 seconds"
      rebootserver(message)
      print "sleeping for 10 seconds"
      time.sleep(10)
      print "aborting shutdown"
      abortreboot()
you will have to create a socket, bind it for example to port 4567, listen on that port for incoming connections and wait for the xbox to connect to send a shutdown packet.



Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply

Logout Mark Read Team Forum Stats Members Help
python script for remote boot up/reboot/shutdown0