Solved

cleaning up output from mysql command in shell script

Posted on 2014-01-22
3
581 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39801527
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
ID: 39807226
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
ID: 39807329
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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

707 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