0

i need to exit from shell script when TESTEXCHANGE process is not running on a host.How can i handle this:

I have a script processcheck which checks if the process is running.

I call that to the MainTest script.I want to exit MainTest script if the ProcessCheck script fails.

cat Processcheck:

while read proc; do
        if (( 0 == $(ps -ef | grep -v grep | grep -c /location) )); then
                echo "!!!!! $proc down on Master TU  !!!!!"
                RC=1
         else
           echo "!!!!!! $proc is still running on Master TU!!!!!"
        fi
#echo "Not checked"

done < /tmp/PROCESSLIST

cat MainTest:

#!/bin/bash

cd /app/utp/bin

ssh Test@TestHost 'bash -s' < /ProcessCheck

i want to exit here if processcheck fails next steps

2
  • What do you mean, "fail" ? You mean when ProcessCheck detects an error and prints !!!!! $proc down on Master TU !!!!!, or when it misbehaves and returns an error ?
    – Aserre
    Aug 27, 2015 at 8:31
  • @Ploutox when it prints "$proc down on Master TU !!!!!,"
    – canonical
    Aug 27, 2015 at 13:23

1 Answer 1

0

You could use exit statuses to deal with your case. Exit statuses are numerical values returned by a command to indicate whether the execution went well or not. The default value is 0 if it was a success, a number between [1..255] otherwise. Each value has a signification.

For instance, you could rewrite your Processcheck like this :

while read proc; do
        if (( 0 == $(ps -ef | grep -v grep | grep -c /location) )); then
                echo "!!!!! $proc down on Master TU  !!!!!"
                RC=1  #I'm not sure why you use this line
                EXIT_STATUS=1
         else
           echo "!!!!!! $proc is still running on Master TU!!!!!"
        fi
#echo "Not checked"

done < /tmp/PROCESSLIST
exit $EXIT_STATUS  #1 means there was an error, 0 means everything went fine

In your MainTest, you can call Processcheck and check its status by looking the variable $?

You must log in to answer this question.

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