Save result ofa xp_cmdshell command

  • I need to check if my remote network is available every 5 mins. I am thinking to use ping.

    Query:

    exec master..xp_cmdshell 'ping 192.***.**.*'

    Base on the output of this query I will know is my network is still available.

    How can I save it in the table then determine from there the reply of the ping.

    This practice seems not a good practice. Do I have other option?

    Any comment is very appreciated.

    Thanks!

  • You can insert..exec into a table.

    insert MyTable exec xp_cmdshell ''

    but you need to match up the result set with the schema correctly

  • Thank you this works for me 😀

    Create Table #Output

    (

    Output varchar(150) default('')

    )

    INSERT INTO #Output

    EXECUTE xp_cmdshell 'ping 192.168.10.1'

    SELECT *

    FROM #Output

  • anvie (2/13/2009)


    Thank you this works for me 😀

    Create Table #Output

    (

    Output varchar(150) default('')

    )

    INSERT INTO #Output

    EXECUTE xp_cmdshell 'ping 192.168.10.1'

    SELECT *

    FROM #Output

    Beautiful. That works well. Thanks!

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply