title: freeTDS bash: Executing sql queries in Microsoft SQL server
body: <p>I am able to connect to a Microsoft SQL Server 2008 instance via a Mint Linux VM using freeTSD and command line to execute sql statements on it. Now I want automate this in a bash script. I am able to successfully login in my bash script:</p>
  
  <pre><code>TDSVER=8.0 tsql -H servername -p 1433 -D dbadmin -U domain\\Administrator -P password
  </code></pre>
  
  <p>I then have my SQL query:</p>
  
  <pre><code>USE dbname GO delete from schema.tableA where ID &gt; 5 GO delete from schema.tableB where ID &gt; 5 GO delete from schema.tableC where ID &gt; 5 GO exit
  </code></pre>
  
  <p>This works when doing manually via freeTSD command line, but not when I put in bash file. I followed this post: <a href="https://stackoverflow.com/questions/5445374/bash-script-makes-connection-using-freetds-interacts-doesnt-exit-just-hangs">freeTSD &amp; bash</a>.</p>
  
  <p>Here is my bash script sample:</p>
  
  <pre><code>echo "USE dbname GO delete from schema.tableA where userid &gt; 5 go delete from schema.tableB where userid &gt; 5 go delete from schema.tableC where ID &gt; 5 GO exit" &gt; tempfile | TDSVER=8.0 tsql -H servername -p 1433 -D dbname -U domain\\Administrator -P password &lt; tempfile
  </code></pre>
  
  <p>the output of the bash script is:</p>
  
  <pre><code>locale is "en_US.UTF-8"
  locale charset is "UTF-8"
  Default database being set to sbdb
  1&gt; 2&gt; 3&gt; 4&gt; 5&gt; 6&gt; 7&gt; 8&gt; 
  </code></pre>
  
  <p>and then the rest of my script is executed.</p>
  
  <p>Can someone give me a step by step answer to my problem ?</p>