DBA's often need to execute the same set of scripts against multiple instances. The job is made a lot easier by using a windows batch file that executes a sqlcmd against all the instances one after the other. All the server names can be placed in a text file and the below code parses thru the text file one after the other and executes sqlcmd against them. The output of each sqlcmd command is logged to the file 'output.txt'. '>>' is the operator that appends the output to the same text file each time sqlcmd runs rather than creating a new file and over-writing it every time.
@echo off
for /F "tokens=*" %%a in (servernames.txt) do sqlcmd -S%%a -E -i "C:\check\script.sql" >> "C:\check\output.txt" -b
@echo off
for /F "tokens=*" %%a in (servernames.txt) do sqlcmd -S%%a -E -i "C:\check\script.sql" >> "C:\check\output.txt" -b
No comments:
Post a Comment