mail program on shell script didn't work, please advise.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting mail program on shell script didn't work, please advise.
# 1  
Old 09-21-2006
mail program on shell script didn't work, please advise.

Hi, everyone:

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

# 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 "Subject Line" myemail@company.com < updt_attrib.log

exit 0

Last edited by duke0001; 09-22-2006 at 12:39 PM..
# 2  
Old 09-21-2006
Quote:
Originally Posted by duke0001
mail -s myemail@company.com < updt_attrib.log
You're passing the subject line switch but not putting one in so it's using your e-mail address as a subject line.

Carl
# 3  
Old 09-21-2006
Carl:

You are right. But do I have to put subject line there? If not, it will cost problem? There is any default subject line?
# 4  
Old 09-21-2006
Quote:
Originally Posted by duke0001
Carl:

You are right. But do I have to put subject line there? If not, it will cost problem? There is any default subject line?
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.

Carl
# 5  
Old 09-21-2006
Carl:

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.
# 6  
Old 09-21-2006
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 ([]).

Code:
  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.

Code:
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.

Code:
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.

Carl
# 7  
Old 09-22-2006
may be give a try with mailx command instead of mail.
As BOFH suggested these things must be checked specially with path of log file
Code:
mailx -s "sub" urmail@xyz.com<datafile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Optimizing the Shell Script [Expert Advise Needed]

I have prepared a shell script to find the duplicates based on the part of filename and retain latest. #!/bin/bash if ; then mkdir -p dup fi NOW=$(date +"%F-%H:%M:%S") LOGFILE="purge_duplicate_log-$NOW.log" LOGTIME=`date "+%Y-%m-%d %H:%M:%S"` echo... (6 Replies)
Discussion started by: gold2k8
6 Replies

2. Shell Programming and Scripting

[Crontab] didn't work

Hello, Here is my crontab # Reboot one Sunday out of 2 at 02:00 0 2 * * 0/2 /usr/bin/reboot 2017-04-16 2017-04-23 2017-04-30 and so on I tested my crontab here, it seems to work Http://cron.schlitt.info/index.php?c...=100&test=Test However on my distrib linux mageďa When I register... (4 Replies)
Discussion started by: amazigh42
4 Replies

3. Shell Programming and Scripting

Portable shell script advise

All, I have a need for a portable shell script for LInux and HPUX. The script has a simple need; Check for local files of a specific name (i.e. filename*), scp them to another system, and archive them to a folder. The script runs via cron. I first wrote the script in Linux (bash with gnu... (4 Replies)
Discussion started by: hburnswell
4 Replies

4. UNIX for Dummies Questions & Answers

emulate aix 5.3 , how ....? pearpc didn't work

how to emulate aix 5.3 i had try pearpc , but it didn't work ... someone have some solution? thanks (1 Reply)
Discussion started by: prpkrk
1 Replies

5. SCO

Hard disk clone of OpenServer 5.0.0 didn't work, why?

Continuing saga of working on making a retail store more robust by creating a backup clone of the main server, a 1995 era :eek: PC running SCO OpenServer 5.0.0b and a discontinued Point of Sales (POS) software system. I have a PC of the same make and model. The CPU runs faster and it has a... (5 Replies)
Discussion started by: jgt10
5 Replies

6. Programming

Please give me some advise to program for unix/linux using c/c++?

I have a good foundation of c++.I want to learn to program for linux/unix,can you give me some advises,for example classic books ,which operating system is used better(freebsd,solaris,federal linux.etc),and which aspects uses mostly in job.Can you give me clear direction for working or learning. (1 Reply)
Discussion started by: fengshuiyue
1 Replies

7. Shell Programming and Scripting

SED - replace with new line didn´t work for solaris

Hi This is what I was trying to do, comment one line and add something different in a new line right next. This is the command I want to do more .profile | sed 's,STRING1, #STRING1 NEWLINE STRING2,' (I´m using ',' because my string is something like this exec... (3 Replies)
Discussion started by: alcalina
3 Replies

8. UNIX for Dummies Questions & Answers

starce didn't work

Hello, I am learning to debug in sgi-Irix6.5, after a core dump, I was adviced to perform a "strace", but I got the following information: ERROR: tracer already exists what shall I do now? Thanks a lot Daniel (0 Replies)
Discussion started by: lakeat
0 Replies

9. Shell Programming and Scripting

script to start DB didn't work, help

I have created a script to strat and shutdown Oracle 10g DB on Solaris automatically when UNIX reboot. In the begining, it worked well. All of sudden, the dbstart part didn't work, other 3 part for lsnrctl, emctl, isqlplusctl all worked fine. I think it was TNS_ADMIN variable got problem. Because... (0 Replies)
Discussion started by: duke0001
0 Replies

10. Shell Programming and Scripting

script didn;t work in cron !!! @_@

Hi all, I am writing a script to monitor some processes existence in the system. It works perfectly by running the script manually in commend line. However, when I put it under cron to run it failed. Everything time when the variable is null in the if statment. it failed and quitted. Here is... (2 Replies)
Discussion started by: stancwong
2 Replies
Login or Register to Ask a Question