1

I am trying to find specific service and I have question about this command:

service --status-all | grep worker

Why did service --status-all | grep ... not work?

1
  • 1
    In what way didn't it work, exactly? did you see something you didn't expect to see, or not see something that you did expect to see? Jun 11, 2015 at 12:00

3 Answers 3

2

There could be one of 2 issues here.

  1. Either you have no process called worker - I didn't. Try to grep for kill or dm - you should see something for them.

  2. You are seeing all of them. This is because it's giving it as lots of individual outputs, not just 1 thing.

    Each of those lines is printed separately, and it's as stderr not stdout. You have 2 options.

    1. Redirect to a file, like this:

      service --status-all > allout.txt 2>&1
      

      All the output will be saved in a file called allout.txt. You can then cat and grep that:

      cat allout.txt | grep worker
      

      That can be combined to one command:

      service --status-all > allout.txt 2>&1 && cat allout.txt | grep worker
      
    2. Redirect stderr to /dev/null, and grep stdout:

      service --status-all 2>&1 > /dev/null | grep worker
      

    Both of these give the same output:

    tim@Hairy14:~$ service --status-all > allout.txt 2>&1 && cat allout.txt | grep kill
     [ ? ]  killprocs
    

    and

    tim@Hairy14:~$ service --status-all 2>&1 > /dev/null | grep kill
     [ ? ]  killprocs
    
2

You can easily use the hack double Tab

once you run :

sudo service wo 

then double Tab this would automcplete or list all services startting with wo


you can still use grep if your terminal support colors

for example here is a test for my services:

 service --status-all | grep vnstat

enter image description here

0
0

Use:

service --status-all |& grep worker

service --status-all | grep vnstat
1
  • 1
    Please explain what the commands are doing! Jul 26, 2018 at 13:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .