Ubuntu – The “service –status-all | grep thesql” get many unrelated result
command linegrepservices
It seems weird here while running
service --status-all | grep mysql
why I get so many wrong result?
It works fine on Centos where i am getting:
mysql is running xxxxxxx
This is what i am getting on Ubuntu:
Best Answer
service --status-all shows its output on both STDOUT (file descriptor 1) and STDERR (file descriptor 2), with the services for which the status can be determined on STDOUT (indicated by [+] or [-]) and the services whose status can not be determined on STDERR (indicated by [?]).
While doing service --status-all | grep mysql, you are running grep over only the STDOUT of service --status-all, that's why everything showing on STDERR are being shown (along with the possible output of grep).
To get only the desired result, redirect both run redirect both STDOUT and STDERR to grep:
Best Answer
service --status-all
shows its output on both STDOUT (file descriptor 1) and STDERR (file descriptor 2), with the services for which the status can be determined on STDOUT (indicated by[+]
or[-]
) and the services whose status can not be determined on STDERR (indicated by[?]
).While doing
service --status-all | grep mysql
, you are runninggrep
over only the STDOUT ofservice --status-all
, that's why everything showing on STDERR are being shown (along with the possible output ofgrep
).To get only the desired result, redirect both run redirect both STDOUT and STDERR to
grep
:Test:
Look at the signs inside
[]
: