我希望监视 SQL Server 维护计划中可能发生的各种事件。我想要的方法是让维护计划对数据进行 HTTP POST。经过一些研究,我认为我的首选方法是使用 cURL,但我知道这需要启用 xp_cmdshell,从安全角度来看这并不理想。
所以,我试图把一些 T-SQL 放在一起,它会检查 xp_cmdshell 是否启用,如果没有启用它足够长的时间来运行命令,然后再次禁用它。但是,我下面的内容不是合作的,我很确定这与所有这些 GO 的...
DECLARE @cmdstatus INT
SET @cmdstatus = (SELECT CONVERT(INT, ISNULL(value, value_in_use)) AS config_value FROM sys.configurations WHERE name = N'xp_cmdshell')
IF @cmdstatus = 1
EXEC xp_cmdshell 'curl --user user:password --data "task=test&status=success" https://www.example.ca/index.php';
GO
IF @cmdstatus = 0
EXEC sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
EXEC sp_configure 'xp_cmdshell', 1;
GO
RECONFIGURE;
GO
EXEC xp_cmdshell 'curl --user user:password --data "task=test&status=success" https://www.example.ca/index.php';
GO
EXEC sp_configure 'xp_cmdshell', 0;
GO
RECONFIGURE;
GO
EXEC sp_configure 'show advanced options', 0;
GO
RECONFIGURE;
GO
谢谢你的帮助。