-2

I'm trying to write up a power cycling Python script to test an external system. One part of the script is that the off-time between the iterations of power off and power on must be variable, and so I'm looking for any UNIX and/or Python command or set of commands that can trigger the boot-up of a system.

I've considered simply using the -shutdown.exe -r -t 00 UNIX command but that doesn't allow for a time delay between off and on.

Albus Dumbledore
  • 11,500
  • 22
  • 60
  • 102
atf
  • 47
  • 11

2 Answers2

0

AFAIK there is no such thing out of the box (for non-advanced-server HW). To switch on the machine you must probably write into the BIOS settings. The BIOS may have a power-on date/time. Maybe you can alter BIOS settings, read here: https://serverfault.com/questions/498557/is-it-possible-to-change-bios-settings-from-linux

Anyway, if power cycle isn't really needed, you can put the machine in a diferent run level: http://www.tldp.org/LDP/sag/html/run-levels-intro.html

Community
  • 1
  • 1
PeterMmm
  • 22,286
  • 12
  • 68
  • 104
  • unfortunately, a power cycle is needed... a full power down and boot is required to accurately complete the test – atf Oct 21 '15 at 21:05
0

The solution may depend on the OS and BIOS of the external system. For example, under Ubuntu this sets the machine to wake up in 5 minutes and then shuts down the machine:

sudo sh -c "echo 0 > /sys/class/rtc/rtc0/wakealarm"
sudo sh -c "echo `date '+%s' -d '+ 5 minutes'` > /sys/class/rtc/rtc0/wakealarm"  
sudo shutdown -h now

I learned this here.

If the above commands work on your system, then you can incorporate them into a Python script, using subprocess.call to call the commands.

unutbu
  • 711,858
  • 148
  • 1,594
  • 1,547
  • The OS i'm using is either Windows 7 or 8.1. How would I go about doing this in the command prompt? – atf Oct 21 '15 at 21:04
  • [Here](http://www.kozeniauskas.com/itblog/2008/01/18/remotely-change-bios-settings/) they talk about set bios settings from Windows. – PeterMmm Oct 23 '15 at 14:59