Reputation: 25
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
Upvotes: 1
Views: 287
Reputation: 75478
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")"
Upvotes: 2