LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 04-05-2009, 12:29 PM   #1
Geneset
Member
 
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
G
 
Old 04-05-2009, 02:08 PM   #2
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 85
Quote:
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:
Code:
rob:~$ mysql -uusername -p <<-EOF 2>>mysql.err 1>>mysql.out
> select * from testdb.contacts;
> select * from testdb.nosuchtable;
> EOF
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 
rob:~$
 
  


Reply

Tags
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 04:09 AM
'sh' shell - Actually calls legacy Bourne shell, or uses system default? Dtsazza Linux - Software 1 10-28-2005 09:20 AM
Bash Shell vs Bourne infamous41md Linux - Newbie 14 04-11-2003 10:16 PM
Bourne Again SHell help MagInnovision Linux - Newbie 2 02-04-2003 03:43 PM
Bourne shell programming noodle123 Programming 3 04-16-2002 03:46 AM


All times are GMT -5. The time now is 10:57 AM.

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