Create a gist now

Instantly share code, notes, and snippets.

"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