LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-26-2016, 06:51 AM   #16
RagingRaven
Member
 
Registered: Sep 2011
Location: Oud-Beijerland, The Netherlands
Distribution: Mageia 4
Posts: 62

Original Poster
Rep: Reputation: Disabled

Quote:
Originally Posted by keefaz View Post
You can put the command in a subshell like
Code:
( command -args "bla" & )
Ok, but do I still need to redirect to /dev/null or not?

So in other words would my line become?:

Code:
( mysql -u${mysqlUser} -p${mysqlPass} -Ae"FLUSH TABLES WITH READ LOCK; SELECT SLEEP(86400)" & )
or?:

Code:
( mysql -u${mysqlUser} -p${mysqlPass} -Ae"FLUSH TABLES WITH READ LOCK; SELECT SLEEP(86400)" & ) > /dev/null 2>&1
Thanks
 
Old 10-26-2016, 06:56 AM   #17
RagingRaven
Member
 
Registered: Sep 2011
Location: Oud-Beijerland, The Netherlands
Distribution: Mageia 4
Posts: 62

Original Poster
Rep: Reputation: Disabled
Thank you keefaz!

using
Code:
( mysql -u${mysqlUser} -p${mysqlPass} -Ae"FLUSH TABLES WITH READ LOCK; SELECT SLEEP(86400)" & ) > /dev/null 2>&1
I'm finally rid of the output generated.
 
Old 10-26-2016, 06:56 AM   #18
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,308
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
The latter.

You'll want to look up a little bit about subshells, redirects, and background processes that you are using here. They will be useful in other situations. Some starting points:

http://mywiki.wooledge.org/SubShell
http://mywiki.wooledge.org/BashGuide...ut#Redirection
http://mywiki.wooledge.org/ProcessMa..._background.3F

There is other good reading material elsewhere, too.
 
Old 10-26-2016, 07:08 AM   #19
RagingRaven
Member
 
Registered: Sep 2011
Location: Oud-Beijerland, The Netherlands
Distribution: Mageia 4
Posts: 62

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
The latter.

You'll want to look up a little bit about subshells, redirects, and background processes that you are using here. They will be useful in other situations. Some starting points:

http://mywiki.wooledge.org/SubShell
http://mywiki.wooledge.org/BashGuide...ut#Redirection
http://mywiki.wooledge.org/ProcessMa..._background.3F

There is other good reading material elsewhere, too.
Thanks Turbo, I'll take a look at it, I understand the basics, but this looks a little more in depth.
 
Old 10-26-2016, 02:59 PM   #20
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by RagingRaven View Post
Code:
( mysql -u${mysqlUser} -p${mysqlPass} -Ae"FLUSH TABLES WITH READ  LOCK; SELECT SLEEP(86400)" & ) > /dev/null 2>&1
I'm finally rid of the output generated.
yes, but does the script do what it should?
i'm pretty sure that this:
Quote:
Originally Posted by RagingRaven View Post
Just tried with set -e -x and it is indeed the last line that's outputting.
What I did see though was that the command shown was:
Code:
mysql -u<user> -p<pass> '-AeKILL QUERY <id>;'
Which seems different from what's in my code, not only missing the > /dev/null 2>&1 part, but also having single quotes and missing double quotes:
Code:
mysql -u${mysqlUser} -p${mysqlPass} -Ae"KILL QUERY ${SLEEP_ID};" > /dev/null 2>&1
means that there MUST be a space between -Ae and "KILL QUERY ${SLEEP_ID};", so it should read:

Code:
mysql -u${mysqlUser} -p${mysqlPass} -Ae "KILL QUERY ${SLEEP_ID};" > /dev/null 2>&1
try that again.
 
Old 10-26-2016, 04:23 PM   #21
RagingRaven
Member
 
Registered: Sep 2011
Location: Oud-Beijerland, The Netherlands
Distribution: Mageia 4
Posts: 62

Original Poster
Rep: Reputation: Disabled
@ondoho

Even though there is no space between -e and the query, it does appear to be working fine.


Code:
mysql -u${mysqlUser} -p${mysqlPass} -Ae"FLUSH TABLES WITH READ LOCK; SELECT SLEEP(86400)" &
works because I can see a query running when looking at the processlist.


Code:
mysql -u${mysqlUser} -p${mysqlPass} -Ae"KILL QUERY ${SLEEP_ID};"
also works, because after this command the correct query is no longer running.

So although I agree with you that it looks better to add a space, it doesn't appear necessary

The command itself was never the issue though, that was working fine, it was the output I couldn't get rid of.
Luckily, with a little help from keefaz, it's fixed now though.

Last edited by RagingRaven; 10-26-2016 at 04:26 PM.
 
  


Reply

Tags
mysql, output, redirect, stderr, stdout



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
Can i redirect any command to dev null? postcd Linux - General 3 04-18-2014 10:03 AM
[SOLVED] Perl: redirect STDERR from system() call to /dev/null totaluser Linux - Newbie 2 11-25-2011 02:30 AM
/dev/null file mod changes won't stick on reboot wonderboy1999 MEPIS 10 09-04-2007 11:07 AM
Redirect X windows / GUI to /dev/null? mattfr Linux - Software 9 12-20-2004 09:40 AM
Outputting Command Text to /dev/null rootking Linux - Software 4 12-19-2004 07:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:37 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration