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
Solved

cleaning up output from mysql command in shell script

Posted on 2014-01-22
3
577 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
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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…

856 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