I need to occasionally monitor a spider that I have running on my server. I'm testing it to see how many iterations of it are running concurrently and to see if any of them are hanging.

I use this:

echo `ps -ewwo args | grep '^[^ ]*curl'`

and the output is all in one line. If I change that to

echo `ps -ewwo args | grep -n '^[^ ]*curl'`

I get the line numbers, but the output is still all in one line. How do I get it to break the results into separate lines?

As a test, I did something like

grep "br" /home/user/www/index.php

and it found many instances and output them each on a separate line, just like I want I to.

  • 5
    Why are you using echo here at all? – Michael Hampton Dec 18 '13 at 20:33
  • Michael is correct, your use of echo with no double quotes is the root cause of your whitespace problems. – glenn jackman Dec 18 '13 at 20:33
  • At this point, I am pretty much a copy and paste admin, so I found that online. I tried taking it out of the echo and my output was NULL (I think I got that from bbs.archlinux.org/viewtopic.php?pid=791164 ) – TecBrat Dec 18 '13 at 20:34
  • I tried it again. I must have made a mistake when I pulled it out of the echo before. When I just did ps -ewwo args | grep -n '^[^ ]*curl' it worked – TecBrat Dec 18 '13 at 20:38
  • Mickael, If you'll make that an answer, I'll give you credit for it. – TecBrat Dec 18 '13 at 20:39

If you don't quote the output of a `...` subshell, the linebreaks will be replaced with spaces. If you want the linebreaks then don't use a `...` subshell, just run the commands and let them do the outputting by themselves, without using echo at all, for example:

ps -ewwo args | grep '^[^ ]*curl'
ps -ewwo args | grep -n '^[^ ]*curl'

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.