Unix Technical Forum

Executing a reboot command from SQL

This is a discussion on Executing a reboot command from SQL within the SQL Server forums, part of the Microsoft SQL Server category; --> Here is the block of the sproc that I?ve created. All lines execute fine except for the ?exec master..xp_cmdshell ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 02:35 AM
Steve Duke
 
Posts: n/a
Default Executing a reboot command from SQL

Here is the block of the sproc that I?ve created. All lines execute
fine except for the ?exec master..xp_cmdshell @reboottc?. In order to
make this work from the query analyzer I had to set the MSSQLSERVER
service to have the same credentials as the thin clients we are trying
to shut down, that means the service is running as an Administrator on
the sql server with the same u/p as administrator on thin clients.


declare @RoomNumber varchar(6) -- for testing

set @RoomNumber = '1144' -- for testing

DECLARE @RoomIP varchar(15), @RebootTC
varchar(120), @shutdownStart varchar(20), @shutdownEnd varchar(85)



-- @ShutDownStart and @ShutDownEnd will be used
with the @RoomIP to build the shutdown command sent to the thin
clients

SET @ShutDownStart = 'shutdown -r -f -m \\'

SET @ShutDownEnd = ' -t 5 -c "Mandatory
iConnect Reboot issued during guest check in/out process"'



SELECT @RoomIP = IP FROM Rooms WHERE
RoomNumber = cast(@RoomNumber AS INT)



SET @RebootTC = @ShutDownStart + @RoomIP +
@ShutDownEnd



-- print @RebootTC -- for testing



-- @RebootTC ends up looking like the line below based on the
@RoomNumber

-- shutdown -r -f -m \\172.18.16.103 -t 5 -c "Mandatory iConnect
Reboot issued during guest check in/out process?

-- Also the command below runs correctly when executed from SQL Query
Analyzer


EXEC master..xp_cmdshell @RebootTC
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 02:36 AM
Simon Hayes
 
Posts: n/a
Default Re: Executing a reboot command from SQL


"Steve Duke" <steveduke@Comcast.net> wrote in message
news:d374a58d.0404231159.230def1c@posting.google.c om...
> Here is the block of the sproc that I?ve created. All lines execute
> fine except for the ?exec master..xp_cmdshell @reboottc?. In order to
> make this work from the query analyzer I had to set the MSSQLSERVER
> service to have the same credentials as the thin clients we are trying
> to shut down, that means the service is running as an Administrator on
> the sql server with the same u/p as administrator on thin clients.
>


<snip>

I admit that I haven't looked at your code in detail, but all code executes
on the server, so any xp_cmdshell commands execute as the server, not the
client. That means that if you want a command to shut down servers or
workstations, then you'll have to give those permissions to the MSSQL or SQL
Server Agent proxy service account (see "xp_cmdshell" in Books Online). You
might want to look at doing this outside MSSQL, unless you have a compelling
reason to do it in the database.

Simon


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:11 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com