A simple Startup and Shutdown script for your unRAID Server


Recommended Posts

Hi there. The past week I've been toying with creating a startup and a shutdown script for my unRAID server. The holy grail to switch both on and off my server via two scripts was what I wanted. This makes like easy for those who need to use your unRAID server, to be able to power it on and off without any intervention, or getting an inexperienced person to log on unRAID web gui, shutting down, etc... The 'startup' script works assuming WOL works fine for your server. Below is the 'startup' script, which you simply copy the text, paste into a blank Notepad session, edit according to your setup and save as a 'start_unraid.bat'. For WOL, I use "mc-wol.exe", which is a free download and can easily be Googled, but feel free to use any DOS-based WOL utility if you like.

 

 

@echo off

echo .

echo ===========================================

echo =  Now Powering on the "YOUR_SERVER_NAME" Server.  =

echo ===========================================

echo =          To cancel, TERMINATE THIS SCRIPT NOW!        =

echo ===========================================

ping -n 5 localhost >nul

C:\path\to\the\wolfile\mc-wol.exe aa:bb:cc:dd:ee:ff

echo .

echo =============================

echo =  The server will be ready in 2 mins.  =

echo =============================

ping -n 5 localhost >nul

 

 

Below is a VB Script, with all thanks and credits going to "StevenD" and "barrettj" for creating, amending and assisting me with it. Simply copy the text, paste into a blank Notepad session, edit according to your setup and save as a 'stutdown_unraid.vbs':

 

 

ServerName = "YOUR_SERVER_NAME"

UserName = "root" 'Admin name'

Passwd = "YOUR_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

 

 

 

Just copy the startup and shutdown scripts to your PC, create shortcuts to them to your desktop and change the icon to something distinguishable, if you like. You could even set these as part of your startup/shutdown scripts to be excuted when your media PC Starts up/Shutdown, so no intervention what so ever is required, and your Media PC and server will be up and running by only turning on just the media PC.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.