1

I want to check if parsoid service is running. So I run this command:

service --status-all|grep 'parsoid'

But the result is:

 [ ? ]  aliyun-rdate

 [ ? ]  console-setup

 [ ? ]  dns-clean

 [ ? ]  irqbalance

 [ ? ]  killprocs

 [ ? ]  kmod

 [ ? ]  mysql

 [ ? ]  networking

 [ ? ]  ondemand

 [ ? ]  pppd-dns

 [ ? ]  rc.local

 [ ? ]  sendsigs

 [ ? ]  umountfs

 [ ? ]  umountnfs.sh

 [ ? ]  umountroot

Why? shouldn't grep be able to speak parsoid screened out of it?

Jahid
  • 21,542
  • 10
  • 90
  • 108
user3875388
  • 541
  • 1
  • 6
  • 19
  • 8
    Perhaps `service --status-all` writes to stderr as well ? Can you try `service --status-all 2>&1 | grep 'parsoid' ` – nos Jun 15 '15 at 10:28
  • 1
    If you want the status of a specific service then ask `service` for the status of that service instead of asking for the status of every service. – Etan Reisner Jun 15 '15 at 11:21

1 Answers1

2

Try:

service --status-all 2>&1|grep -o 'parsoid'

1 is stdout and 2 is stderr.

> is for redirection

& specifies that what follows is a file descriptor (not a filename)

2>&1 redirects stderr to stdout and then the stdout is piped into the grep

Note: service --status-all writes to stderr.

Jahid
  • 21,542
  • 10
  • 90
  • 108
  • 2
    I'd drop an explanation of `2>&1` into your answer too for those discovering this later. Or just refer to this answer https://stackoverflow.com/questions/818255/in-the-shell-what-is-21 – Olical Jun 15 '15 at 14:03