LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How get a mysql shell response in a script. (https://www.linuxquestions.org/questions/programming-9/how-get-a-mysql-shell-response-in-a-script-158328/)

philipina 03-16-2004 04:00 AM

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.

TreeHugger 03-16-2004 06:27 AM

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

philipina 03-16-2004 06:48 AM

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.

TreeHugger 03-16-2004 11:51 AM

'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?!


All times are GMT -5. The time now is 11:51 PM.