Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2011
    Posts
    14

    Unanswered: 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 06:08.

  2. #2
    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:

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

    > 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:

    > 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:

    > 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 04:45.

  3. #3
    Join Date
    Aug 2011
    Posts
    2
    You might also want to try the "-table" argument for mysql.

    Wayne

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •