I’m trying to write a script to check several functions return and in case of return 1 write in the log file and send me an email, but loop is not working as expected:
- In case of success print everything good
- In case update fails it writes in log two lines “failed” and “done” and sends me an email.
Could you please help to find a mistake?
w2log() {
if [[ $? = 0 ]] ; then
echo "=== Everything looks good ! DONE `date` ===" >> $LOG;
else
echo "=== Something went wrong ! FAILED `date` ===" >> $LOG && errmail
fi
}
updaterepos() {
syn6332
syn5864
for repo in syn6332 syn5864; do
w2log
done
}
updaterepos
Maybe something like that (if you want a
w2logreport for each command):The function checking
$?should be called immediately after the command returning the status. Function calls also set$?— that’s why you were getting the second “done” line when you calledw2logsecond time.