Declare @Vs_sql Varchar(8000), @Userip Varchar(30), @s Varchar(1000), @Ip Varchar(30), @Result Varchar Declare cur1 cursor for Select PosIp from openrowset('SQLOLEDB','192.168.8.50';'sa';'sa'),SQLDB_USER.dbo.table) open cur1 select @Userip=count(*) from openrowset('SQLOLEDB','192.168.8.50';'sa';'sa'),SQLDB_USER.dbo.table) while @@FETCH_STATUS=0 and @Userip>1 begin fetch next from cur1 into @Ip set @Userip=@Ip-1 print @Ip set @s='''sqlcmd -S '+@Ip+' -U sa -P sa''' print (@s) set oncount on exec @Result=master..xp_cmdshell @Ip, on_output if @Result='0' print '正常' else print '异常' 这样子,执行完显示的所有IP都是异常。
Declare @Vs_sql Varchar(8000), @Userip Varchar(30), @s Varchar(1000), @Ip Varchar(30), @Result Varchar Declare cur1 cursor for Select PosIp from openrowset('SQLOLEDB','192.168.8.50';'sa';'sa'),SQLDB_USER.dbo.table) open cur1 select @Userip=count(*) from openrowset('SQLOLEDB','192.168.8.50';'sa';'sa'),SQLDB_USER.dbo.table) while @@FETCH_STATUS=0 and @Userip>1 begin fetch next from cur1 into @Ip set @Userip=@Ip-1 print @Ip set @s='''sqlcmd -S '+@Ip+' -U sa -P sa''' print (@s) set oncount on exec @Result=master..xp_cmdshell @s, on_output if @Result='0' print '正常' else print '异常' 这样子,执行完显示的所有IP都是异常。
set @s='sqlcmd -S '+@Ip+' -U sa -P sa'这里先改成这样
你改成这样试试,我本机测了一下可以的Declare @Vs_sql Varchar(8000), @Userip Varchar(30), @s Varchar(1000), @Ip Varchar(30), @Result Varchar(1) set @s='sqlcmd -S '+@Ip+' -U sa -P sa' print (@s) set nocount onEXEC @result= master..xp_cmdshell @s if @Result='0' print '正常' else print '异常'
no_output Is an optional parameter, specifying that no output should be returned to the client. If the no_output option is used, only the following will be returned: The command(s) completed successfully. 没必要用这个选项
set nocount on
exec @r=master..xp_cmdshell 'sqlcmd -S 192.168.1.1 -U sa -P sa',no_output
if @r='0'
print '正常'
else
print '异常'把p改成大写试试
@Userip Varchar(30),
@s Varchar(1000),
@Ip Varchar(30),
@Result Varchar
Declare cur1 cursor
for Select PosIp from openrowset('SQLOLEDB','192.168.8.50';'sa';'sa'),SQLDB_USER.dbo.table)
open cur1
select @Userip=count(*) from openrowset('SQLOLEDB','192.168.8.50';'sa';'sa'),SQLDB_USER.dbo.table)
while @@FETCH_STATUS=0 and @Userip>1
begin
fetch next from cur1 into @Ip
set @Userip=@Ip-1
print @Ip
set @s='''sqlcmd -S '+@Ip+' -U sa -P sa'''
print (@s)
set oncount on
exec @Result=master..xp_cmdshell @Ip, on_output
if @Result='0'
print '正常'
else
print '异常'
这样子,执行完显示的所有IP都是异常。
中间打错了,应该是exec @Result=master..xp_cmdshell @s, on_output
Declare @Vs_sql Varchar(8000),
@Userip Varchar(30),
@s Varchar(1000),
@Ip Varchar(30),
@Result Varchar
Declare cur1 cursor
for Select PosIp from openrowset('SQLOLEDB','192.168.8.50';'sa';'sa'),SQLDB_USER.dbo.table)
open cur1
select @Userip=count(*) from openrowset('SQLOLEDB','192.168.8.50';'sa';'sa'),SQLDB_USER.dbo.table)
while @@FETCH_STATUS=0 and @Userip>1
begin
fetch next from cur1 into @Ip
set @Userip=@Ip-1
print @Ip
set @s='''sqlcmd -S '+@Ip+' -U sa -P sa'''
print (@s)
set oncount on
exec @Result=master..xp_cmdshell @s, on_output
if @Result='0'
print '正常'
else
print '异常'
这样子,执行完显示的所有IP都是异常。
@Userip Varchar(30),
@s Varchar(1000),
@Ip Varchar(30),
@Result Varchar(1)
set @s='sqlcmd -S '+@Ip+' -U sa -P sa'
print (@s)
set nocount onEXEC @result= master..xp_cmdshell @s
if @Result='0'
print '正常'
else
print '异常'
Is an optional parameter, specifying that no output should be returned to the client.
If the no_output option is used, only the following will be returned: The command(s) completed successfully.
没必要用这个选项