LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-06-2011, 01:29 PM   #1
Specter1981
LQ Newbie
 
Registered: Sep 2009
Posts: 4

Rep: Reputation: 0
[help needed] [mysql dumps/restores] [bash script] [output redirection]


Hello and thanks for opening my cry out for help. I have been searching the web for an answer to this problem but have failed to find one up to this point and am getting pretty desperate. Don't even know where to ask this question...

So here it is: I am working on a script that is supposed to automatically import a mysql dump to a temporary database, clear some sensitive data, then do a new dump and then send the cleared database to some developpers. For it I need some pretty detailed logs. Here is where I am having the problem:

Code:
mysql -u $MYSQL_ROOT_USER -p$MYSQL_ROOT_PASS ${TEMP_DB} < $WORK_FILE_1 >> $LOG_FOLDER/${DATE_LOG}-movingDB.log 2>&1
My problem is that I can't seem to be logging anything using this method (I was actually hoping that this would be capting all the stdout and stderr streams to ${DATE_LOG}-movingDB.log but that doesn't happen). If I make a mistake in the name of the work file that needs to be imported, well, I get the error message when running the script from the shell but nothing in the logs.

Anyone has any idea what I could do or where I could ask?

Thank you in advance.
 
Old 06-06-2011, 08:34 PM   #2
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 697

Rep: Reputation: 93
It sounds like you want detailed logging of the import process.
By default that doesn't happen. When all is successful, there
is no output from the mysql command.

Try adding the "-v" flag and see if that gives enough output.
If not, keep adding more and see what happens.
 
Old 06-07-2011, 04:17 AM   #3
Specter1981
LQ Newbie
 
Registered: Sep 2009
Posts: 4

Original Poster
Rep: Reputation: 0
thank you very much for taking the time to through some advice my way. Very much appreciated. I tried what you suggested, however the verbose mode is too much. What was important for this script was to record if the command succeeds or if it fails.

So I went around it with the following:

Code:
mysql -u $MYSQL_ROOT_USER -p$MYSQL_ROOT_PASS ${TEMP_DB} < $WORK_FILE_1
RESULT=$?
if [$RESULT -eq 0]
then
  echo "...Done!" >> $LOG_FOLDER/${DATE_LOG}-movingDB.log
else
  echo "...FAIL!" >> $LOG_FOLDER/${DATE_LOG}-movingDB.log
fi
This will at least record if the command worked or not.

HOWEVER, I find it hard to believe no one ever needed this before me. I mean if in the command
Code:
mysql -u $MYSQL_ROOT_USER -p$MYSQL_ROOT_PASS ${TEMP_DB} < $WORK_FILE_1 >> $LOG_FOLDER/${DATE_LOG}-movingDB.log 2>&1
I change the root user to some bogus one, then I get the logging I want. If I change the password to a bogus one I get the logging I want (the standard mysql error messages that would be displayed are redirected to the log file). But if I change something AFTER the < character (i.e. the path to the mysql dump that I want to import), then all I get is an error message onscreen and nothing in the log file. Could anyone explain why that is? (or point me in the right direction please?).

Thank you.

Last edited by Specter1981; 06-07-2011 at 05:25 AM.
 
Old 06-07-2011, 07:27 AM   #4
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 697

Rep: Reputation: 93
Yes, it's a question of what processes each part of the command line.

To start, the shell will replace any variables and set up any redirections.
It then puts all the arguments into a list and starts the command, giving
it the list of arguments. The command then processes the arguments.

Since the redirection is handled by the shell prior to executing the
command, the errors at this stage are not redirected into the log file.
 
1 members found this post helpful.
  


Reply

Tags
mysql, script, stderr, stdout


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
FTP in a Bash Shell Script redirection sleepyhomme Programming 2 05-02-2007 12:53 PM
Output and Error redirection in Shell script (MinGW) montylee Programming 6 09-08-2006 06:06 AM
shell script output redirection goral.j Programming 3 01-27-2005 06:34 AM
bash output redirection: debian vs freebsd kenners Programming 2 10-07-2004 05:56 PM


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

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