4

Our company has a db (SQL Server) in another country. I have the host name, username and the password of the db. I want to extract data from the database through bash shell and put them into local file. How can I do that?

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
TrueBlue10
  • 318
  • 2
  • 4
  • 16

2 Answers2

4

Install FreeTDS. Once configured you'll be able to use tsql to query SQL Server from bash.

Liam Gretton
  • 370
  • 1
  • 8
  • 2
    Hi, I've installed the FreeTDS and connected to the SQL Server. Thank you. But how can I make query? – TrueBlue10 Mar 27 '14 at 13:31
  • 1
    The problem is solved by installing FreeTDS. And the query sentence should be `select * from blah where id = 1` and we need a `go` at the end of query. – TrueBlue10 Mar 28 '14 at 09:27
1

You will need some command line utilities export data from MS SQL Server. One option is to install Microsoft ODBC Driver for SQL Server on Linux and then use some command line utility like sqlcmd.

MSDN page for Microsoft ODBC Driver: http://msdn.microsoft.com/en-us/library/hh568451.aspx

Example of using sqlcmd to export data to a CSV file: How to export data as CSV format from SQL Server using sqlcmd?

Community
  • 1
  • 1
  • I just saw SUSE and redhat version, but my OS is debian. – TrueBlue10 Mar 27 '14 at 13:42
  • 1
    I do not have a Debian to play with, but I found a tutorial here: https://code.google.com/p/odbc/wiki/InstallingMicrosoftDriverOnDebianLinux I hope it works for you. – Razvan Stefanescu Mar 28 '14 at 08:36
  • Hi, thank you for your advice. I tried to install sqlcmd on my OS, but it seems only support 64bit operating system. So I try to use FreeTDS and it works. But thank you very much. – TrueBlue10 Mar 28 '14 at 09:26