Correct example script (#3590)

Previous version could not work as grep -q does not print anything to stdout, only exits with a status code depending on a match was found or not. Hence the variables were always empty and could not be compared with 0
This commit is contained in:
Nope Nope 2017-06-23 01:18:13 +02:00 committed by Misty Stanley-Jones
parent 8f27eeac35
commit 483a8a8370
1 changed files with 4 additions and 2 deletions

View File

@ -59,8 +59,10 @@ this in a few different ways.
# Otherwise it will loop forever, waking up every 60 seconds
while /bin/true; do
PROCESS_1_STATUS=$(ps aux |grep -q my_first_process |grep -v grep)
PROCESS_2_STATUS=$(ps aux |grep -q my_second_process | grep -v grep)
ps aux |grep -q my_first_process |grep -v grep
PROCESS_1_STATUS=$?
ps aux |grep -q my_second_process |grep -v grep
PROCESS_2_STATUS=$?
# If the greps above find anything, they will exit with 0 status
# If they are not both 0, then something is wrong
if [ $PROCESS_1_STATUS -ne 0 -o $PROCESS_2_STATUS -ne 0 ]; then