Solved

cleaning up output from mysql command in shell script

Posted on 2014-01-22
3
564 Views
Last Modified: 2014-01-25
Hello

If i had a shell script which ran a mysql command like so

/usr/bin/mysql -u user -ppassword database_name < /path/file.sql

and the sql file contained an update command, what would happen to the 'number of rows affected' output? Where would it go?

I've seen it cleaned up like this before

> /dev/null

What would happen if dev/null was full?

What would happen if the job running the script did not have permission to access /dev/null? Is this possible?

Thank
0
Comment
Question by:andieje
  • 2
3 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
Comment Utility
The output goes to the "stdout" stream which is by default associated with your terminal.

/dev/null (the null device) is a special file which cannot get full. Everything redirected to it is immediately discarded.

/dev/null is world-writeable.
0
 

Author Comment

by:andieje
Comment Utility
what if it was running in the background? is that why it is sent to /dev/null
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
Comment Utility
When running a job in the background without output redirection you're at risk to get a ENOTTY error, or at least to see (with longer running jobs) out-of-the-blue text messages arriving at your terminal now and then, so it's good practice to redirect the output, be it stdout or stderr, to a logfile or to the said "special" file /dev/null.
It's not at all mandatory to use /dev/null for background jobs, regular log files will do as well.

A particular case is "nohup". When a process is started in the background prepended with "nohup" and the output is not redirected then "nohup" will capture it on its own and redirect it to a file named "nohup.out".
"nohup" is meant to let your job survive even when its parent shell dies.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Issue with cURL on Windows 7 65
Sed question 2 45
Error connecting to mysql on localhost 3 44
mySql Syntax 7 20
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now