Thx for the tips. I don't know that I'm going to use the return code value now since I don't want to have to code all possible return values, but I have more questions. Hope someone can help me understand this.
Notice my script and how I want to test a few levels deep. Can a /bin/sh script even do that? I'm trying to employ a little error correction, reattempts, etc in a sh script.
In the following example I'd like to connect to the database. IF it cannot connect the first time I'd like it to try again. IF it fails on the second attempt I'd like it to rename an output file, email a few of us and exit the script. I'm having trouble with the logic or even knowing if what I want it to do is possible with Bourne shell.
#!/bin/sh
# this is one chunk of the script (nothing uber-sensative)
# the following is me having fun with variables...
EMAIL1=me@mycompany.com #my email
EMAIl2=you@yourcompany.com #email of someone
DB_NM=The_Rings_of_Wrath_and_Khan #the name of the database
USRNM1=ralph.nader #username login credentials
PZWD1=money_is_green_too #$USRNM1's password
#*******************************
# connect to database
#*******************************
db2 connect to $DB_NAME user $USRNM1 using $PZWD1
if [ "$?" = "0" ] then echo "Connected to database"
elif [ "$?" != "0" ] then echo "retrying connection..."
if [ "$?" = "0" ] then echo "Connect to database on 2nd try"
elif [ "$?" != "0" ] then echo "Could not connect to $DB_NAME"|mail -s "non-critical section failure CONNECT TO DATABASE" $EMAIL1 -c$EMAIL2
NOW=`date %Y%m%d%H%M%s` #note those are 'ticks' or shift-tilde, not single quotes
cp output.file output.{$NOW}.file
exit
fi
fi
Can a /bin/sh script do this? Can I embed tests that deep? Do I have to put two 'fis' at the bottom? Is that exit statement near the end necessary? Help appreciated.
ß