If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > missing delimiters when mysql output is redirected to log file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-23-11, 04:37
newbielgn newbielgn is offline
Registered User
 
Join Date: Jul 2011
Posts: 14
missing delimiters when mysql output is redirected to log file

Hi,

Pls check that '|' and '+' present in Step-1 are not copied to log file in Step-3.
Pls suggest how to get the exact output from Step-1 (i.e. with out losing '|' and '+') in to a log file

Thanks

Step-1: Execute command
Code:
> mysql -utest -ptest -htesthost testdb -e "select * from student;"
+---------+--------+------------+
| name    | gender | student_id |
+---------+--------+------------+
|         | M      |          1 |
| newname | M      |          2 |
+---------+--------+------------+
Step-2: Redirect output to log file
Code:
> mysql -utest -ptest -htesthost testdb -e -e "select * from student;" &>log_file
Step-3:Cat contents of log file
Code:
> cat log_file
name    gender  student_id
        M       1
newname M       2

Last edited by newbielgn; 08-23-11 at 05:08.
Reply With Quote
  #2 (permalink)  
Old 08-24-11, 03:37
waynepeer waynepeer is offline
Registered User
 
Join Date: Aug 2011
Posts: 2
I'm a little rusty, and I've never used mysql, so hopefully I won't lead you too far astray. I'm not sure if the output from mysql is normally standard out or error out, or a combination of the two, but if it's standard out, all you need is a greater-than sign followed by the file name. For example:

Quote:
> mysql -utest -ptest -htesthost testdb -e -e "select * from student;" > log_file
If the output is error out, use 2 greater-than, like this:

Quote:
> mysql -utest -ptest -htesthost testdb -e -e "select * from student;" 2> log_file
If the output is both, then redirect standard out to the file, and then redirect error out into standard out, like this:

Quote:
> mysql -utest -ptest -htesthost testdb -e -e "select * from student;" > log_file 2>&1
Just looked up mysql commands online. Looks like you could possibly use "-tee=log_file" as an option and let mysql handle it for you. If you don't want the result to come out on the screen, you can redirect it to oblivion like this:

Quote:
> mysql -tee=log_file -utest -ptest -htesthost testdb -e -e "select * from student;" > /dev/null 2>&1
I hope I haven't confused the issue too much.

Wayne

Last edited by waynepeer; 08-24-11 at 03:45.
Reply With Quote
  #3 (permalink)  
Old 08-24-11, 20:44
waynepeer waynepeer is offline
Registered User
 
Join Date: Aug 2011
Posts: 2
You might also want to try the "-table" argument for mysql.

Wayne
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On