Messaging
cancel
Showing results for 
Search instead for 
Did you mean: 

Problem w/ -s switch on mailx

Problem w/ -s switch on mailx

I'm having a problem where the subject line of a mailx message buried in a HP-UX script is not being passed on the the recipient. I have a test case, which works perfectly, but the production case doesn't. Does anyone have any guidance on where I should suspect the problem is?

Thanks!
11 REPLIES
Sandman!
Honored Contributor

Re: Problem w/ -s switch on mailx

Could you post the mailx command that you are using for both the test and production cases.

~thanks

Re: Problem w/ -s switch on mailx

Here's the prod version that does not work:

#!/usr/bin/ksh
echo 'Script execution begins..........'
export ORACLE_SID=odsdw3
echo "
WHENEVER SQLERROR EXIT FAILURE;
set serveroutput off;
spool /tmp/mks2997.log;
@/hna/scripts/dba_scripts/catapult_tables_refresh.sql
spool OFF;
" | sqlplus @/u01/app/oracle/admin/odsdw3/util/parms.txt
if [[ $? -eq 0 ]]
then
echo "Script successfully executed!"
mailx -s "GDW:DW3:catapult_tables_refresh.sql execution log" mark.frederickson@us.hjheinz.com < /tmp/mks2997.log
exit 0
else
echo "Errors encountered. Check Log!"
mailx -s "GDW:DW3:catapult_tables_refresh.sql execution log" mark.frederickson@us.hjheinz.com < /tmp/mks2997.log
exit 1
fi


Here's the test case that does:

#!/usr/bin/ksh
echo 'Script execution begins..........'
export ORACLE_SID=odsdw3
echo "
WHENEVER SQLERROR EXIT FAILURE;
set serveroutput off;
spool /tmp/MailTest.log;
@/hna/scripts/dba_scripts/MailTest.sql
spool OFF;
" | sqlplus @/u01/app/oracle/admin/odsdw3/util/parms.txt
if [[ $? -eq 0 ]]
then
echo "Script successfully executed!"
mailx -s "GDW:DW3:MailTest.sql execution log" mark.frederickson@us.hjheinz.com < /tmp/mks2997.log
exit 0
else
echo "Errors encountered. Check Log!"
mailx -s "GDW:DW3:MailTest.sql execution log" mark.frederickson@us.hjheinz.com < /tmp/MailTest.log
exit 1
fi

Dennis Handly
Acclaimed Contributor

Re: Problem w/ -s switch on mailx

I'm not sure what's different between the two.
You may need to add "set -x" to trace your problem.

I naturally don't have problems because I change your "sqlplus" to /usr/bin/true or false and I echo something to /tmp/mks2997.log.

Are you saying you don't get mail, or you have the wrong subject?

In your "good" one, you seem to have this inconsistency:
spool /tmp/MailTest.log;

Then you read from either /tmp/mks2997.log (success) or /tmp/MailTest.log (failure).

Re: Problem w/ -s switch on mailx

Dennis,

Thanks for taking the time to look @ this. To answer your questions, I am getting mail, no problem. The issue is that the subject line is not being passed in the prod example. The difference in the file redirection, mks2997.log or MailTest.log makes no difference in the results.

Mark
Sandman!
Honored Contributor

Re: Problem w/ -s switch on mailx

Have you tried interactively running the mailx command line by itself instead of in a script? Would help troubleshooting the issue. Run the command and post the output here.

Re: Problem w/ -s switch on mailx

Yes I have & it works as I would expect. It is only the prod version of the script that is causing me heartburn.

Thanks for contributing to my hopeful resolution, however.
Dennis Handly
Acclaimed Contributor

Re: Problem w/ -s switch on mailx

>The issue is that the subject line is not being passed in the prod example.

It worked for me. Do you get a subject at all? (It would help if your mail subject said whether it was good or bad results. ;-)

Can you add that "set -x" so we can trace your execution path?
I don't see how that -s option can fail. You are quoting it. You don't have any special chars in it. A cut&paste of your example shows one long line. (Are you doing this in crontab?)

>The difference in the file redirection, mks2997.log or MailTest.log makes no difference in the results.

I had to change it so it existed. Otherwise the mail wasn't sent.

(You may want to ask the moderators to disguise/remove your mail address. You may get spam from it. Make your request here:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1157827

>Sandman: Have you tried interactively running the mailx command line by itself instead of in a script?

Hmm, when I diffed the two, the mailx line looked almost the same.

One other thing is the fact that the subject has multiple ":" in it. But both the good and the bad do. Some mail clients may not like it? What do you use to read it?
Dennis Handly
Acclaimed Contributor

Re: Problem w/ -s switch on mailx

Unfortunately /var/adm/syslog/mail.log doesn't seem to record the subject.

Re: Problem w/ -s switch on mailx

>The issue is that the subject line is not being passed in the prod example.

>It worked for me. Do you get a subject at all? (It would help if your mail subject said whether it was good or bad results. ;-)

No, I do not get a subject at all when the prod script is run & I know we should have some kind of indicator of success/failure, but I'm dealing with a third-party out-sourcing organization & they are a bunch of kunckleheads.


>Can you add that "set -x" so we can trace your execution path?

Here's the example with 'set -x' trace on (this test results in a good subject line returned to me):

hgdwtest:mfrederi:/home/mfrederi$log" mark.frederickson@us.hjheinz.com < /tmp/MailTest.log <
+ mailx -s GDW:DW3:MailTest.sql execution log mark.frederickson@us.hjheinz.com
+ 0< /tmp/MailTest.log

>I don't see how that -s option can fail. You are quoting it. You don't have any special chars in it.

I don't see how this could fail either, which is the reason why I thought I would ask you all!


>Are you doing this in crontab?

Yes, the prod script is scheduled with crontab.

>One other thing is the fact that the subject has multiple ":" in it. But both the good and the bad do. Some mail clients may not like it? What do you use to read it?

In my test today, I executed from the command line with the ':' & '.' in place. It still works (and always had @ the cmd-line - it's when run in the prod script that it is a problem).

I am sending this to a MS Outlook client.

Thanks for looking into this!

Mark
Sandman!
Honored Contributor

Re: Problem w/ -s switch on mailx

To troubleshoot further you can look in the "/var/spool/mqueue" dir on prod and see if the mail to be sent out has a Subject line. This eliminates whether the problem is with the server sending out the email or somewhere downstream (mail relay host). Also do the prod and test servers use the same mail relays? After executing the mailx cmd look up its Q-ID and grep for the Subject line i.e.

# cd /var/spool/mqueue
# mailx
--- now get the Q-ID of the email to be sent out
# mailq
# grep Subject qf
Dennis Handly
Acclaimed Contributor

Re: Problem w/ -s switch on mailx

>Here's the example with 'set -x' trace on (this test results in a good subject line returned to me):

Are you saying when you add "set -x" it works? Or you didn't instrument the bad one?

>Sandman: To troubleshoot further you can look in the "/var/spool/mqueue" dir on prod and

Won't you have to stop sendmail so it remains in the queue long enough to look at?