This won't work and is the reason why it doesn't exit properly:
Code:
if
.
.
fi | tee -a /tmp/log;
Try this instead (I also changed some other parts of your code):
Code:
if grep -q 'abcdefgh01.was.db.dcbc' /tmp/hosts
then
echo " HOSTNAME ADDED IN /tmp/hosts" | tee -a /tmp/log
else
echo " HOSTNAME not ADDED IN /tmp/hosts EXITING" | tee -a /tmp/log
exit 1
fi
Here's another way of doing it:
Code:
( if grep -q 'abcdefgh01.was.db.dcbc' /tmp/hosts
then
echo " HOSTNAME ADDED IN /tmp/hosts"
else
echo " HOSTNAME not ADDED IN /tmp/hosts EXITING"
exit 1
fi ) | tee -a /tmp/log