This is very unintuitive.


When a user tries to:

# service --status-all | grep postgres

This won't work...

The only way to grep `service' is:

# service --status-all 2>&1 | grep postgres

On Gentoo Linux for example this problem does not occur:

# rc-status | grep postgres

will work fine.


It might sound a bit strange but it does not. To be more exact, it displays only unknown [?] statuses on the standard error (besides other error messages).

You can see the script in /usr/sbin/services. The relevant part is the following (lines 68--98):

   if [ -z "${SERVICE}" -a $# -eq 1 -a "${1}" = "--status-all" ]; then
      cd ${SERVICEDIR}
      for SERVICE in * ; do
        case "${SERVICE}" in
          functions | halt | killall | single| linuxconf| kudzu)
            if ! is_ignored_file "${SERVICE}" \
        && [ -x "${SERVICEDIR}/${SERVICE}" ]; then
                    if ! grep -qs "\Wstatus)" "$SERVICE"; then
                      #printf " %s %-60s %s\n" "[?]" "$SERVICE:" "unknown" 1>&2
                      echo " [ ? ]  $SERVICE" 1>&2
                      out=$(env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status 2>&1)
                      if [ "$?" = "0" -a -n "$out" ]; then
                        #printf " %s %-60s %s\n" "[+]" "$SERVICE:" "running"
                        echo " [ + ]  $SERVICE"
                        #printf " %s %-60s %s\n" "[-]" "$SERVICE:" "NOT running"
                        echo " [ - ]  $SERVICE"
              #env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status
      exit 0

The echo " [ + ] $SERVICE" line does not print to standard error, and so the [ - ] variant.

You can easily test the above assumption by running: services --status-all 2>/dev/null. If you have any running service that supports the status command, it will be listed.

  • This is great info, thanks, but it still does not answer "why?". The fact that service writes some info to stdout, and some info to stderr, is even more confusing when doing something like service --status-all | less. – kaliatech Nov 13 '12 at 15:18
  • 2
    @kaliatech The script only outputs to stderr if it finds a service that does not support the status option. It is an error from the script's point of view, because it assumes that every service should adhere to the standard. I believe as time goes by, the number of [?] statuses will be greatly reduced and eventually disappear. – lgarzo Nov 13 '12 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.