Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Could someone please provide help for me.

I tried to start writing a shell script but am getting hung up with this issue. I need to grep commands "adb shell ps" and find in it 3 processes with names:

  1. proc1
  2. proc2
  3. proc3

And if these processes are present in the grep output, then continue work with the script, else check the grep 5 times within the interval - 30 seconds. Finally - if my process doesn't start, just exit form script.

share|improve this question

closed as unclear what you're asking by Gilles, jasonwryan, paraxor, Anthon, manatwork Aug 9 '13 at 8:00

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Can you clarify what's the question? You need to find 'adb shell ps' in proc1/2/3 logs or what? Is the process the one you're checking or process's logs ? –  user1293137 Aug 8 '13 at 10:14

1 Answer 1

Here's a script that does what I think you're looking for:

#!/bin/bash

cnt=1; found=0;
while [ "$cnt" -le 5 ]; do
  echo "chk#: $cnt"
  if [[ $(pgrep -f "proc1") && $(pgrep -f "proc2") && $(pgrep -f "proc3") ]]; then
    found=1
    break
  fi
  let cnt=cnt+1
  sleep 6
done

[ "$found" -eq 0 ] && exit

echo "found them"

You can change this line out if the proc1, proc2, & proc3 are the actual names of the processes. The above looks for any occurrence of those strings in the command lines.

  if [[ $(pgrep "proc1") && $(pgrep "proc2") && $(pgrep "proc3") ]]; then

The script makes use of pgrep instead of grep since this command can essentially do a ps .. | grep ... in a single command.

share|improve this answer

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