Skip to content

Instantly share code, notes, and snippets.

@cixelsyd
Created December 17, 2011 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cixelsyd/1491439 to your computer and use it in GitHub Desktop.
Save cixelsyd/1491439 to your computer and use it in GitHub Desktop.
"createdb.rb" recipe needs a templated batch file to execute arbitrary T-SQL
:: chef template <%= @executesql_template %>
:: becomes "<%= @executesql_bat %>" on the server
:: generic execute sql wrapper - <%= @author_name %> / <%= @author_email %>
:: requires chef / internet connectivity to opsware git repo
:: initial version 2011:09:19 15:01:00 EST
:: pass SQL sa passwd as ARG1
:: pass SQL script as ARG2
:: pass SQL logfile as ARG3
:: NOTE -> SQL SERVER 2008 ships with sa login "DISABLED"
:: THIS IS STUPID ON A LEVEL I CAN'T EVEN BEGIN TO APPROACH
:: NOT ONLY THAT, but SQL SERVER 2008 on AWS is configured for windows auth only
@echo off
cls
:: "globally"
set workingDirectory=<%= @working_dir %>
set sqlcmdPath=<%= @sqlcmd_path %>
set sqlsausername=<%= @sqlsausername %>
echo.execute arbitrary sql passed as %2
echo.log to arbitrary file passed as %3
cmd /c "%sqlcmdPath%\sqlcmd.exe" -S %COMPUTERNAME% -U %sqlsausername% -P %1 -i %workingDirectory%\%2 -o %workingDirectory%\%3.log
echo.chef timestamping the logfile
cmd /c "date /t" >> %workingDirectory%\%3.log
cmd /c "time /t" >> %workingDirectory%\%3.log
echo.arbitrary SQL script %2 done
:: cleaup environment vars before exit
set workingDirectory=
set sqlcmdPath=
set sqlsausername=
echo.batch environment var cleanup done
exit /B 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment