1

I'm trying to grep the command df -h with a pattern that comes from a mysql command. Right now I have something like this:

df -hP | grep $(mysql -uroot -e "select statement")

Right now this is trying to grep the result of the mysql query instead of using the result as the pattern to grep the df result

The result of the mysql statement is "raid_48"

I will then want to pipe this into mailx. Maybe I shouldn't be trying to do this with a one liner

3
  • Well, what is wrong then? Commented Jul 14, 2014 at 20:11
  • Can you add the output of $(mysql -uroot -e "select statement") depending on what it returns it may break grep syntax. Commented Jul 14, 2014 at 20:14
  • If grep is trying to process raid_48 as a file instead of an expression, try adding -e as also suggested in my answer. Commented Jul 14, 2014 at 20:24

1 Answer 1

2

If there may be something wrong with your command you can consider these:

# Add `-e` before the argument to explicitly tell grep that the argument that follows is an expression not an option.
# Quote your argument to prevent word splitting with spaces.
df -hP | grep -e "$(mysql -uroot -e "select statement")"

# Perhaps try using fgrep as well to prevent reading argument as regex.
df -hP | fgrep -e "$(mysql -uroot -e "select statement")"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.