LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-13-2016, 02:56 AM   #1
gszabo
LQ Newbie
 
Registered: Sep 2015
Posts: 11

Rep: Reputation: Disabled
Dump tsql result to a file


Hello,

I'd like to run mssql queries in a bash script with tsql command. Thats okay, i can connect and run manualy. I tried to save the result to a file with this script but no success.

> tsql -connection parameters- < tsql_input.sql > tsql_output.csv

where tsql_input.sql is :

select ... from .... ;
 
Old 05-15-2016, 02:23 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,837

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
what's happening (so what is the expected result and what is the real result)?
 
Old 05-17-2016, 02:33 AM   #3
gszabo
LQ Newbie
 
Registered: Sep 2015
Posts: 11

Original Poster
Rep: Reputation: Disabled
Hello Pan64,

Thanks for the reply. After running the script above i got this in tsql_output.csv file :

locale is "C"
locale charset is "ANSI_X3.4-1968"
using default charset "ISO-8859-1"
locale is "C"
locale charset is "ANSI_X3.4-1968"
using default charset "ISO-8859-1"
1> 2> 3> 4> 5> 6> 7> 8>

If i run just the tsql to connect the server i got a "1>" prompt where i can send commands like select * from... and i got the results there. thats okay. I just unable to run it from a script.

I have a simple "select.. from.." query in tsql_input.sql file, and it's result i want to dump to the output file.

Last edited by gszabo; 05-17-2016 at 02:36 AM.
 
Old 05-17-2016, 02:48 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,837

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
if I understand well you may need expect to do that.
 
Old 05-17-2016, 08:54 AM   #5
gszabo
LQ Newbie
 
Registered: Sep 2015
Posts: 11

Original Poster
Rep: Reputation: Disabled
As i see expect will be a good option, but finally i solved the problem with this way :

/usr/bin/tsql ...parameters.... < cmd > $tempfile

where cmd is

SELECT .... FROM ...
GO
EXIT
 
Old 08-17-2017, 12:40 AM   #6
anooprerna
LQ Newbie
 
Registered: Aug 2017
Posts: 4

Rep: Reputation: Disabled
Question TSQL and Linux - Getting the export of a select command

Hello gszabo,

I'm stuck with the exact same problem.

When I fire this command, I don't get the output captured to the /home/anoop/capture_output.txt file. Instead, it simply connects me the Database.

tsql -H abcd.com -D DBName -p 1433 -U anoop -P somepassword select @@version go exit /home/anoop/capture_output.txt

locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Setting DBName as default database in login packet
1>

Would you be able to help me with this please?
 
Old 08-17-2017, 01:53 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,837

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
I'm afraid, gszabo will not respond, his last activity was at 10th Jun 2016 13:26.
Probably would be better to open a new thread...
 
1 members found this post helpful.
Old 08-17-2017, 02:13 AM   #8
anooprerna
LQ Newbie
 
Registered: Aug 2017
Posts: 4

Rep: Reputation: Disabled
Smile

Hello pan64,

Many Thanks for the suggestion. I've opened a new thread now.

I see that you've proposed to use "expect". I did explore on that without much luck. Would you be able to provide me a sample syntax for that?
 
  


Reply

Tags
bash, sql



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
restore file or dir from dump file brumela Linux - Newbie 7 01-19-2023 08:20 AM
[SOLVED] How to write ping result in a log file/text file ablopera Linux - Newbie 3 07-13-2015 06:56 AM
bash -D (or bash --dump-strings) unexpected result Ubx Linux - General 2 02-24-2011 06:41 PM
Core dump issues. Program crashes but does not generate core dump file sabeel_ansari Programming 1 10-07-2009 04:23 PM
How to forcely dump the history of user commands to the admin dump file. mcp_achindra Linux - Security 1 03-19-2004 12:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration