Expand bash script for linux into threads

This is a follow up to a question I had last night, where I got pretty good help right away(make a long story short, login to a webserver was solved using PERL)

What I want to expand on now, is as following; we have Nagios 3 running, and AFAIK it uses the exit codes to determine wether or not to raise an alarm.

It is in that spirit I've written this script as posted below.
It works now that if it finds one of the combinations of username/password incorrect in the external script it calls, it will then return an error code, move to the "else" and then post a log, before it exits with code 2 for ERROR

What I want todo, is if it is down, it should exit with error code 2, but before that, also check the 3 others.

How can I tell what error code it is to use at the end if it is to check all 3. Now it stops at the first that fails.

#!/bin/sh
 
echo ""
echo "||----------------------------------------||"
echo "|| GroupWise WebAccess sjekker            ||"
echo "|| Laget av Rune Darrud, BKB Data         ||"
echo "|| Versjon 4 - 18 november, 2008          ||"
echo "||----------------------------------------||"
echo ""
 
LOGGFIL=./logg.txt
GWWEBACC=./webacc
TEMPSAK=./temp.temp
PK1=./postkontor1.sh
PK2=./postkontor2.sh
PK3=./postkontor3.sh
 
# Date
DATE=$(date "+%Y.%m.%d %T")
 
TEXTTING=Login
PK1NAVN="****"
PK2NAVN="****"
PK3NAVN="****"
 
# Checking if the front page exists.
wget -q --no-check-certificate https://webmail/gw/webacc -O $GWWEBACC > $TEMPSAK
grep -q "$TEXTTING" $GWWEBACC
if [ $? -eq 0 ]
then 
 rm $GWWEBACC
 rm $TEMPSAK
else
 rm $GWWEBACC
 rm $TEMPSAK
 exit 2
fi
 
# Checking the first login
perl $PK1 > $TEMPSAK
grep -q "$PK1NAVN" $TEMPSAK
if [ $? -eq 0 ]
then
 rm $TEMPSAK
else
 rm $TEMPSAK
 exit 2
fi
 
# Checking the second login
perl $PK2 > $TEMPSAK
grep -q "$PK2NAVN" $TEMPSAK
if [ $? -eq 0 ]
then
 rm $TEMPSAK
else
 rm $TEMPSAK
 exit 2
fi
 
# Checking the third login
perl $PK3 > $TEMPSAK
grep -q "$PK3NAVN" $TEMPSAK
if [ $? -eq 0 ]
then
 rm $TEMPSAK
else
 rm $TEMPSAK
 exit 2
fi
echo $DATE - OK : ALT OK! >> $LOGGFIL
 
# Rydder opp
exit 0

Open in new window

LVL 2
TheFlyingCorpseAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

amit_gCommented:
Add

ExitCode=0

in the beginning and then change all

exit 2

to

ExitCode=2

then in the end add

exit ExitCode
amit_gCommented:
The last line

echo $DATE - OK : ALT OK! >> $LOGGFIL

should be changed to

if [ $ExitCode -eq 0 ]
then
 echo $DATE - OK : ALT OK! >> $LOGGFIL
else
 exit $ExitCode
fi

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TheFlyingCorpseAuthor Commented:
Thanks for your quick reply amit_g,

I was unable to get it to work at first, but after I saw that I had used ExitCode AND EXITCODE (I use variables in capital letters to see them easier), the problem got solved.


Thank you very much!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.