November 10, 2008 at 9:33 pm
Hi,
I am new to this, I need to understand this script, can you tell me why we are using the xp_cmdshell, szVersion etc... here, what is its purpose. It is part of a db backup script
---For version 9 on free up xp_cmdshell
select @szVersion = Substring (@@version, CharIndex ('-', @@version) + 2,1)
if @szVersion > '8'
begin
exec sp_configure 'show advanced options', 1
reconfigure
exec sp_configure 'xp_cmdshell', 1
reconfigure
end
--Get the environment variable DBBackupPath
--The last part should be 'Backup'
set @Env VarName = 'DBBackupPath'
set noCount on
create table #EnvirmentVariables (output varchar(1000) NULL)
insert #EnvirmentVariables exec master..xp_cmdshell 'set'
Select @BackupPath = Substring (output, CharIndex ('=', output) + 1, len(output) - NULLIF(CharIndex('=',output),-1))
from #EnvirmentVariables where
upper (@Env VarName) = upper (Substring(output, 1, NULLIF(CharIndex9'=', output)-1,-1)))
drop table #EnvirmentVariables
November 10, 2008 at 9:40 pm
sid_sarkar (11/10/2008)
Hi,I am new to this, I need to understand this script, can you tell me why we are using the xp_cmdshell, szVersion etc... here, what is its purpose. It is part of a db backup script
---For version 9 on free up xp_cmdshell
select @szVersion = Substring (@@version, CharIndex ('-', @@version) + 2,1)
if @szVersion > '8'
begin
exec sp_configure 'show advanced options', 1
reconfigure
exec sp_configure 'xp_cmdshell', 1
reconfigure
end
--Get the environment variable DBBackupPath
--The last part should be 'Backup'
set @Env VarName = 'DBBackupPath'
set noCount on
create table #EnvirmentVariables (output varchar(1000) NULL)
insert #EnvirmentVariables exec master..xp_cmdshell 'set'
Select @BackupPath = Substring (output, CharIndex ('=', output) + 1, len(output) - NULLIF(CharIndex('=',output),-1))
from #EnvirmentVariables where
upper (@Env VarName) = upper (Substring(output, 1, NULLIF(CharIndex9'=', output)-1,-1)))
drop table #EnvirmentVariables
xp_cmdshell executes the command at the Operating system level.
Executing this xp_cmdshell statement returns a directory listing of the current directory.
xp_cmdshell 'dir *.exe'
you can refer this link
http://msdn.microsoft.com/en-us/library/aa260689.aspx
kshitij kumar
kshitij@krayknot.com
www.krayknot.com
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply