Jump to content

Any way to send a power off command to a unRAID server on your LAN?


Guest smnas

Recommended Posts

Guest smnas

Hi all. I use a WOL LAN packet to power on my unRAID server when me and my wife need it on. To power off, I either have to go to the Web GUI of my unRAID server and gracefully power it off or physically press the power button (with the help of the "poweroff" script), which will switch it off gracefully too.

My question is it possible to script something in either in VBS, in a *.bat file or something that you can execute on a desktop to power off your unRAID server gracefully? The setup that I have makes it easy for my wife to power my unRAID on, as she just has to double-click on a shortcut to a *.bat file labeled "Power On unRAID", which is scripted for a WOL utility to wake up my server. I want to do the same as a power off command. Any ideas or has someone implemented this too, if so, how did you do it? Hope to hear your thoughts, Cheers!

Link to comment

Put this in a VBS:

 

ServerName = "tower"

UserName = "root" 'Admin name'

Passwd = "password" 'Password'

Power = "powerdown" 'call powerdown script'

DELAY = 500 ' Minimum 500ms recommended; 1000 works well.

 

' --------------------------------------------------------------------

' SECTION B: Start a Shell

' --------------------------------------------------------------------

Set WshShell = WScript.CreateObject("WScript.Shell")

 

' --------------------------------------------------------------------

' SECTION C: Start the TELNET

' --------------------------------------------------------------------

WshShell.Run "cmd.exe /c telnet.exe " + ServerName

' --------------------------------------------------------------------

' SECTION D: Login. ("Sleep" pauses are needed delays.)

' --------------------------------------------------------------------

WScript.Sleep DELAY

WshShell.SendKeys Username + vbLf

WScript.Sleep DELAY

WshShell.SendKeys Passwd + vbLf

WScript.Sleep DELAY

WshShell.SendKeys Power + vbLf

 

I use this because I have my big UPS hooked up to one of my domain controllers. It sends out shutdown commands to the three servers on the UPS (one of which is unraid) in the event of a power outage.

Link to comment

My question is it possible to script something in either in VBS, in a *.bat file or something that you can execute on a desktop to power off your unRAID server gracefully?

 

You can power off your unRAID from any browser by pointing the browser to the following URL:

http://Tower/update.htm?shutdown=apply

 

And if you can do that, then you can also create an Internet Shortcut on your desktop that's pointing to the same URL.

Doubleclicking on that shortcut (or invoking its name from a .bat file) will power off your server.

 

The above assumes that you're using windows.

 

If you're using Linux, then the following line in a script will do the job:

wget http://Tower/update.htm?shutdown=apply 

 

Link to comment
Guest smnas

Hhhhmmm, It worked, but not WOL doesn't work. I had to run a command on my unRAID box to get WOL working at the start. I'll have to sort the WOL issue and I'll report back.

Link to comment

Hi. I tried this and it is a handy script, but the only thing I don't like is:

 

- It doesn't do the sync command to sync all disks before sleeping,

- The telnet session doesn't go away once the server has slept.

 

Is there a way in the vb script to have the above done? I tried to do this, but Im no good when it comes to scripting. Thanks.

 

Put this in a VBS:

 

ServerName = "tower"

UserName = "root" 'Admin name'

Passwd = "password" 'Password'

Power = "powerdown" 'call powerdown script'

DELAY = 500 ' Minimum 500ms recommended; 1000 works well.

 

' --------------------------------------------------------------------

' SECTION B: Start a Shell

' --------------------------------------------------------------------

Set WshShell = WScript.CreateObject("WScript.Shell")

 

' --------------------------------------------------------------------

' SECTION C: Start the TELNET

' --------------------------------------------------------------------

WshShell.Run "cmd.exe /c telnet.exe " + ServerName

' --------------------------------------------------------------------

' SECTION D: Login. ("Sleep" pauses are needed delays.)

' --------------------------------------------------------------------

WScript.Sleep DELAY

WshShell.SendKeys Username + vbLf

WScript.Sleep DELAY

WshShell.SendKeys Passwd + vbLf

WScript.Sleep DELAY

WshShell.SendKeys Power + vbLf

 

I use this because I have my big UPS hooked up to one of my domain controllers. It sends out shutdown commands to the three servers on the UPS (one of which is unraid) in the event of a power outage.

Link to comment

This is untested, but should send the sync command and close the telnet window:

 

ServerName = "tower"

UserName = "root" 'Admin name'

Passwd = "password" 'Password'

Power = "powerdown" 'call powerdown script'

ExitCommand = "exit" 'exit command'

SyncCommand = "sync" 'sync command'

DELAY = 500 ' Minimum 500ms recommended; 1000 works well.

 

' --------------------------------------------------------------------

' SECTION B: Start a Shell

' --------------------------------------------------------------------

Set WshShell = WScript.CreateObject("WScript.Shell")

 

' --------------------------------------------------------------------

' SECTION C: Start the TELNET

' --------------------------------------------------------------------

WshShell.Run "cmd.exe /c telnet.exe " + ServerName

' --------------------------------------------------------------------

' SECTION D: Login. ("Sleep" pauses are needed delays.)

' --------------------------------------------------------------------

WScript.Sleep DELAY

WshShell.SendKeys Username + vbLf

WScript.Sleep DELAY

WshShell.SendKeys Passwd + vbLf

 

' Send sync command

WScript.Sleep DELAY

WshShell.SendKeys SyncCommand + vbLf

 

' send power down command

WScript.Sleep DELAY

WshShell.SendKeys Power + vbLf

 

' Wait for the previous command to be sent then exit the telnet session, then exit the command prompt

WScript.Sleep DELAY

WScript.Sleep DELAY

WshShell.SendKeys ExitCommand + vbLf

WScript.Sleep DELAY

WshShell.SendKeys ExitCommand + vbLf

 

Link to comment

OK, I'll try it and see how it works. Thanks.

If you are installing the "powerdown" script, you better invoke it as /sbin/powerdown

otherwise you'll get the one unRAID supplies that some have reported just powers the server down without stopping it first.

 

Also, if using the "powerdown" script written by WeeboTech, it does perform a "sync" on its own before shutting down the server.

 

Joe L.

Link to comment

At present, I'm using the 's3.sh' script to sleep my server after all hard drives are powered down. I was using 'powerdown' command before, but if I use this, wol magic packets don't work, as why I resorted to using the s3.sh script, it works fine and boots in seconds.

Link to comment

Instead of the 'powerdown' command in the vbscript, I would like to use the s3.sh command to place my server to sleep upon running this, see my script below:

 

ServerName = "unraid"

UserName = "root" 'Admin name'

Passwd = "******" 'Password'

sleep = "/boot/config/s3.sh" 'call sleep script'

ExitCommand = "exit" 'exit command'

SyncCommand = "sync" 'sync command'

DELAY = 500 ' Minimum 500ms recommended; 1000 works well.

 

' --------------------------------------------------------------------

' SECTION B: Start a Shell

' --------------------------------------------------------------------

Set WshShell = WScript.CreateObject("WScript.Shell")

 

' --------------------------------------------------------------------

' SECTION C: Start the TELNET

' --------------------------------------------------------------------

WshShell.Run "cmd.exe /c telnet.exe " + ServerName

' --------------------------------------------------------------------

' SECTION D: Login. ("Sleep" pauses are needed delays.)

' --------------------------------------------------------------------

WScript.Sleep DELAY

WshShell.SendKeys Username + vbLf

WScript.Sleep DELAY

WshShell.SendKeys Passwd + vbLf

 

' Send sync command

WScript.Sleep DELAY

WshShell.SendKeys SyncCommand + vbLf

 

' send sleep command

WScript.Sleep DELAY

WshShell.SendKeys sleep + vbLf

 

' Wait for the previous command to be sent then exit the telnet session, then exit the command prompt

WScript.Sleep DELAY

WScript.Sleep DELAY

WshShell.SendKeys ExitCommand + vbLf

WScript.Sleep DELAY

WshShell.SendKeys ExitCommand + vbLf

 

I'll give it a try and see how I went, my server is busy atm, kinda don't want it to sleep now. Thanks.

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...