LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-16-2004, 04:00 AM   #1
philipina
Member
 
Registered: May 2003
Posts: 77

Rep: Reputation: 15
How get a mysql shell response in a script.


Hello,

I'm doing a script for an automatic logging in MYSQL and I would like to analyse the reply to know if loging was succesfull or not.
I tried a lot of thing, but nothing work

szReply=mysql -u root -ppassword database
mysql -u root -ppassword database>szReply
mysql -u root -ppassword database|mysql -u root -ppassword database

How can I do to get the response in szReply or put it in a file.

Thanks in advance.
 
Old 03-16-2004, 06:27 AM   #2
TreeHugger
Member
 
Registered: Jul 2003
Location: London
Distribution: Debian, Redhat
Posts: 98

Rep: Reputation: 15
I'm not sure if it will help your logging, because as far as I know, executing sql on the command line only outputs errors to the shell, not anything else. But this is what I would do:

cat sqlcommands.sql | mysql -u you -p pw database > output.log 2>&1

where your commands are in sqlcommands.sql
 
Old 03-16-2004, 06:48 AM   #3
philipina
Member
 
Registered: May 2003
Posts: 77

Original Poster
Rep: Reputation: 15
Thanks a lot, this really help me, but I have one more question.

Why this line is working:
mysql -u you -p pw database > output.log 2>&1
and not
mysql -u you -p pw database > output.log
The second line is not working?? where is the difference?

Thanks.
 
Old 03-16-2004, 11:51 AM   #4
TreeHugger
Member
 
Registered: Jul 2003
Location: London
Distribution: Debian, Redhat
Posts: 98

Rep: Reputation: 15
'2>&1' redirects the standard error stream (2) to the standard output stream (1).

Are you working with it interactively? How on earth can you tell what's going on if you capture all the console output?!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
PHP Shell Script (with MySql) Tony Empire Programming 1 09-20-2005 09:59 AM
MySQL in a shell script?! zaubara Programming 2 05-31-2004 05:27 PM
MySQL connection in shell script - how to? philipz Programming 3 04-29-2004 07:04 PM
Import records to MySQL Database from a shell script chrisk5527 Linux - General 12 03-24-2004 09:49 PM


All times are GMT -5. The time now is 10:47 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration