How to code a script to power-off or power-on a server?

Is it possible that there is a script which can accomplish the following function----
1.When Mikrotik detected that there is no station on line in the midnight, shutdown automaticlly;
2.When there is one or above one station on line, it would power automaticlly.

By the way, there are two question.
Question one:
when I use “sys shutdown” command to quit the Mikrotik,Mikrotik is close, but the computer is still on power,how to power off the computer by script?
Question two:
Succeed the question one, how to power on a computer by a script or command ,when I use “sys shutdown” command to quit the Mikrotik?

a) the command halts the system. As far as I know you cannot power it off.
b) when the system is powered down, it’s impossible to run a script to power it on. The script cannot run on a halted or powered down machine. You could use a second device to send a Wake-On-LAN packet, if the device running RouterOS supports that. WOL only works on powered on machines and not on halted machines, so you’re still limited by a)

You need RouterOS 4.x to be able to power down your computer.

Thank you both much.

If you’re looking to save power, use a routerboard instead of a computer. There are routerboards suited for most applications now.

Hey Michael12345, is this was you looking for: “Wake on Lan an internal server”

http://wiki.mikrotik.com/wiki/Manual:Tools/Wake_on_lan