I post a new thread because previous post may sink and I hope the new one can be caught by your eyes.
I created a shell script and the script works fine. However, the mail program part on script didn't send email to my email box and it also didn't provide any traceable infomation. I post the part of code here, please help me to see the coding for mail program part is right or wrong. I append all information to a log file and send the log file content to my email box. Is this right way to invoke mail program on UNIX?
I have tested mail program on that server as: mail -s "test" myemail@company.com. It works well. It means that mail program on server is working. Only thing is my code on scripts. Please advise. Thanks.
----------------------------------------------------------
date +"%D %T: Database $ORACLE_SID is up and running." >> updt_attrib.log
echo "" >> updt_attrib.log
date +"%D %T: update xxxxxxxx script started." >> updt_attrib.log
No default subject line. If you use the -s switch, you must pass a subject line. You don't have to use the -s switch though. It just won't have a subject line when you receive it.
You are right. I have modified script to add subject line like: mail -s 'subject line' myemail@company.com < log file. The script was executed successfully. But mail program still didn't work to send email to my email box. Do you think the syntex of my script correct? Thanks.
You might consider using the "code" constructs when posting scripts. It keeps the script bit in a mono-face font and doesn't break lines. Like that @ line that follows the sqlplus line. Is that supposed to be on its own line or part of the line above it?
When you create a message, click on the pound sign (#) icon above the text and you'll get a code dialog box. I think most people who have experience posting know about the CODE constructs and just type them in (along with QUOTE, URL, and IMG constructs). They work very much like HTML coding except instead of using less than and greater than signs (<>) they use open and close brackets ([]).
date +"%D %T: Database $ORACLE_SID is up and running." >> updt_attrib.log
echo "" >> updt_attrib.log
date +"%D %T: update xxxxxxxx script started." >> updt_attrib.log
# Starte sql script to update xxxxx tables.
sqlplus -s > temp.log 2>&1 dbuser/password@oracle_sid
@tools/sql_script_name.sql
if [ $? = 0 ]
then
date +"%D %T: $scripts successfully executed." >> updt_attrib.log
else
date +"%D %T: Error executing script." >> updt_attrib.log
grep "ORA-" temp.log >> updt_attrib.log
date +"%D %T: Exiting script." >> updt_attrib.log
exit 1
fi
done
date +"%D %T: End update xxxxx in xxxx tables." >> updt_attrib.log
echo "" >> updt_attrib.log
mail -s myemail@company.com < updt_attrib.log
exit 0
I wrapped your script in the code constructs and then cleaned it up the way I might write the script. I didn't see any syntax errors but I also don't see the beginning of the script (should start with a #!/bin/ksh for example). There's a "done" statement with no start so it's hard to say if there are other errors we're not seeing.
Since the log file should still be where ever it is, you should be able to run the mail command by itself and see if it works. If you're running it out of cron, you might not have mail in your path.
mail -s "subject line" myemail@company.com < updt_attrib.log
Additionally your log could be anywhere. I'd normally have the full path for a log file and even set it in a variable (like $LOG) to make it harder to generate a typo.
LOG=/tmp/updt_attrib.log
You might consider putting the whole script in place. Also you can put a "set -x" at the beginning which turns on additional output that might tell you where your script is failing.
Thanks. I should do some code constructs when I posted here. So I have modified my first post and make it looks better. As for log file is concerned, the log file has been generated in the directory of shell script stored. I append all info to log file. I don't think it is the path issue for log file.
I just comment out the "done" in the bottom line. The script is working just fine. I have got what I need. I think the "done" code stop the script process. I take it off. script works.