Visit the LQ Articles and Editorials section
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 04-05-2009, 01:29 PM   #1
Registered: Jan 2007
Location: Athlone, ROI
Distribution: Ubuntu Hardy Desktop, Solaris 10, Workstation 2008 x64
Posts: 75

Rep: Reputation: 16
Question Catching mysql errors in bourne shell

Hi guys, quick one today.

I am writing a logging function for my script library with functions like logger_error, logger_info, logger_debug and logger_trace.

I have a script that automated some mysql transactions across a few servers where due to changes in configuration, i get errors.

Basically, i want to not change where stdout goes (currently it goes to logger_info) and pipe stderr to logger_error.

Redirections dont work.

Have googled endlessly for stderr piping and got some really good attempts but none seem to work for the mysql client.

A bash example would be acceptable but i would prefer a posix or bourne example.

Has anyone come across this before that can gimme a hand? Many regards
Old 04-05-2009, 03:08 PM   #2
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 88
Originally Posted by Geneset View Post
Redirections dont work.
How are you trying to do the redirection? In order to redirect stderr, you use its file descriptor (2) - a very simple example:
rob:~$ mysql -uusername -p <<-EOF 2>>mysql.err 1>>mysql.out
> select * from testdb.contacts;
> select * from testdb.nosuchtable;
Enter password:
rob:~$ cat mysql.out
name	telephone	appid
Rob	09876 123456	1
Carol	01274 245326	NULL
Jeremy	0895 123456	NULL
John	0116 7891234	1
rob:~$ cat mysql.err
ERROR 1146 (42S02) at line 2: Table 'testdb.nosuchtable' doesn't exist 


bourne, mysql, pipe, redirection, stderr

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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
catching output and errors with popen c++ mshindo Programming 2 02-04-2009 05:09 AM
'sh' shell - Actually calls legacy Bourne shell, or uses system default? Dtsazza Linux - Software 1 10-28-2005 10:20 AM
Bash Shell vs Bourne infamous41md Linux - Newbie 14 04-11-2003 11:16 PM
Bourne Again SHell help MagInnovision Linux - Newbie 2 02-04-2003 04:43 PM
Bourne shell programming noodle123 Programming 3 04-16-2002 04:46 AM

All times are GMT -5. The time now is 12:07 PM.

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