Prev: Strategy for data partition?
Next: Syntax error, permission violation, or other nonspecific error when preparing a procedure call
From: Ada on 29 Jun 2010 22:48 Hello, I am running a script against a list of SQL Servers using a DOS Batch file. The .bat generates one output file per SQL Server instance. I can use the destination SQL Server names in the output file names, but I can not use the destination machine names. It brings the lcal machine name and use it on all the out put files. Could you tell me how I can achieve that? set dt=none set tm=none for /F "tokens=2-4 delims=/ " %%i in ('date /t') do set dt=%%i%%j%%k for /F "tokens=5-6 delims=:. " %%i in ('echo.^| time ^| find "current" ') do set tm=%%i%%j for /F %%a in (SQL2005servers.txt) do sqlcmd -E -S %%a -d master -i c:\iSEC\ROG_iSEC-SQLSr_2005_2008_201006220000.sql -Y30 -s "|" -o c:\iSEC\OUT2005\ROG_SQL_Server_%COMPUTERNAME%_%%a_%dt%%tm%.out Thanks, -- Ada SQL Server DBA
From: Erland Sommarskog on 30 Jun 2010 17:29 Ada (Ada(a)discussions.microsoft.com) writes: > I am running a script against a list of SQL Servers using a DOS Batch > file. The .bat generates one output file per SQL Server instance. I can > use the destination SQL Server names in the output file names, but I can > not use the destination machine names. It brings the lcal machine name > and use it on all the out put files. > > Could you tell me how I can achieve that? > > set dt=none > set tm=none > for /F "tokens=2-4 delims=/ " %%i in ('date /t') do set dt=%%i%%j%%k > for /F "tokens=5-6 delims=:. " %%i in ('echo.^| time ^| find "current" ') > do > set tm=%%i%%j > for /F %%a in (SQL2005servers.txt) do sqlcmd -E -S %%a -d master -i > c:\iSEC\ROG_iSEC-SQLSr_2005_2008_201006220000.sql -Y30 -s "|" -o > c:\iSEC\OUT2005\ROG_SQL_Server_%COMPUTERNAME%_%%a_%dt%%tm%.out More of a DOS programming question than an SQL Server question. Right now you have %COMPUTERNAME% in the output file, and that is of course your local machine. But I am not really sure what you are looking for. The SQL Server name is usually the same as the machine name, so wouldn't that be sufficient? But it would be problematic with named instances because of the backslash. Personally, I would use Perl, if I needed to something like this. -- Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se Links for SQL Server Books Online: SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
From: Ada on 30 Jun 2010 22:49 I just want to see host names of the connected SQL Server in the output file names. It's part of the requirements to cover named instance, clusters etc. Thanks, -- SQL Server DBA "Erland Sommarskog" wrote: > Ada (Ada(a)discussions.microsoft.com) writes: > > I am running a script against a list of SQL Servers using a DOS Batch > > file. The .bat generates one output file per SQL Server instance. I can > > use the destination SQL Server names in the output file names, but I can > > not use the destination machine names. It brings the lcal machine name > > and use it on all the out put files. > > > > Could you tell me how I can achieve that? > > > > set dt=none > > set tm=none > > for /F "tokens=2-4 delims=/ " %%i in ('date /t') do set dt=%%i%%j%%k > > for /F "tokens=5-6 delims=:. " %%i in ('echo.^| time ^| find "current" ') > > do > > set tm=%%i%%j > > for /F %%a in (SQL2005servers.txt) do sqlcmd -E -S %%a -d master -i > > c:\iSEC\ROG_iSEC-SQLSr_2005_2008_201006220000.sql -Y30 -s "|" -o > > c:\iSEC\OUT2005\ROG_SQL_Server_%COMPUTERNAME%_%%a_%dt%%tm%.out > > More of a DOS programming question than an SQL Server question. Right > now you have %COMPUTERNAME% in the output file, and that is of course > your local machine. But I am not really sure what you are looking for. > The SQL Server name is usually the same as the machine name, so wouldn't > that be sufficient? > > But it would be problematic with named instances because of the backslash. > > Personally, I would use Perl, if I needed to something like this. > > > -- > Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se > > Links for SQL Server Books Online: > SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx > SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx > SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx > > . >
From: Erland Sommarskog on 1 Jul 2010 03:02 Ada (Ada(a)discussions.microsoft.com) writes: > I just want to see host names of the connected SQL Server in the output > file names. It's part of the requirements to cover named instance, > clusters etc. But does c:\iSEC\OUT2005\ROG_SQL_Server_%%a_%dt%%tm%.out not meet that bill? -- Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
From: Dan on 1 Jul 2010 07:14
"Erland Sommarskog" <esquel(a)sommarskog.se> wrote in message news:Xns9DA85C0189CF7Yazorman(a)127.0.0.1... > Ada (Ada(a)discussions.microsoft.com) writes: >> I just want to see host names of the connected SQL Server in the output >> file names. It's part of the requirements to cover named instance, >> clusters etc. > > But does c:\iSEC\OUT2005\ROG_SQL_Server_%%a_%dt%%tm%.out not meet that > bill? It should - the %%a variable is the instance being connected to as defined in the SQL2005servers.txt file. -- Dan |