Script fails to send out email when HOSTNAME is included


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script fails to send out email when HOSTNAME is included
# 1  
Old 04-26-2017
Bug Script fails to send out email when HOSTNAME is included

Hi,

Below is my script which sends out emails.

Code:
more test.sh
  1 #!/bin/ksh
  2 {
  3         print "From: Prod@mycomp.com"
  4 #        print "From: Prod@`hostname`.com"
  5 #        print "From: Prod@${HOSTNAME}.com"
  6         print "To: me@mycomp.com"
  7         print "Subject: Usage Report"
  8         print "<html>"
  9         print "<body>"
 10         print "</body>"
 11         print "</html>"
 12 } | /usr/sbin/sendmail -t

The above script works fine and i am able to receive emails.

However, Instead of line 3 if i use line 4 or line 5 the script runs but i DO NOT RECEIVE any emails !!

Can you please suggest solutions for line 4 or line 5 which embeds the hostname in the From: section of the email to work ?

Code:
uname -a
SunOS mymac 5.11 11.3 sun4u sparc SUNW,SPARC-Enterprise


Last edited by mohtashims; 04-27-2017 at 05:00 AM..
# 2  
Old 04-27-2017
What do `hostname` and ${HOSTNAME} evaluate to on your server? I suspect that they may give you the fully qualified name, to which you are then appending .com

Try running the script with set -x inserted on line 2 and see if that illustrates the problem. You can also add the -v flag to sendmail for some feedback showing you what's going on.



Robin
# 3  
Old 04-27-2017
Check the mail error log; mayhap the mails are rejected by a / the receiver as spam, e.g. based on the sender domain?
# 4  
Old 04-27-2017
Bug

Quote:
Originally Posted by RudiC
Check the mail error log; mayhap the mails are rejected by a / the receiver as spam, e.g. based on the sender domain?
Can you tell me where can i find those mail logs for Solaris ?

---------- Post updated at 05:31 AM ---------- Previous update was at 05:23 AM ----------

Quote:
Originally Posted by rbatte1
What do `hostname` and ${HOSTNAME} evaluate to on your server? I suspect that they may give you the fully qualified name, to which you are then appending .com

Try running the script with set -x inserted on line 2 and see if that illustrates the problem. You can also add the -v flag to sendmail for some feedback showing you what's going on.



Robin
I enabled set -x as well as verbose for the sendmail. Below is the differences between a successful email received (left hand) proceeds by the output from run with failed email.

Code:
1.

+ print 'From: Prod@mycomp.com'      vs         + print 'From: Prod@mymac.com'

2.

220 mymac.com ESMTP Sendmail 8.15.1+Sun/8.15.1; Thu, 27 Apr 2017 04:39:31 -0500 (CDT)    vs    220 mymac.com ESMTP Sendmail 8.15.1+Sun/8.15.1; Thu, 27 Apr 2017 04:41:12 -0500 (CDT)

3.
 >>> MAIL From:<user1@mymac.com> SIZE=94    vs     >>> MAIL From:<user1@mymac.com> SIZE=105

4. 
050 250-USD11CXB30CN02.biller.com Hello [10.6.140.57]     vs    050 250-USD11CXB30CN05.biller.com Hello [10.6.140.57]

5.
050 >>> MAIL From:<user1@mymac.com> SIZE=350     vs    050 >>> MAIL From:<user1@mymac.com> SIZE=361

6.
050 250 2.6.0 <201704270939.v3R9dVXc012460@mymac.com> [InternalId=59867549145530, Hostname=AUSYD11XB30CN02.biller.com] Queued mail for delivery
050 <Prod@mycomp.com>... Sent (<201704270939.v3R9dVXc012460@mymac.com> [InternalId=59867549145530, Hostname=AUSYD11XB30CN02.biller.com] Queued mail for delivery)
250 2.0.0 v3R9dVjp012461 Message accepted for delivery
Prod@mycomp.com... Sent (v3R9dVjp012461 Message accepted for delivery)


vs


050 250 2.6.0 <201704270941.v3R9fCOO014990@mymac.com> [InternalId=57724360464094, Hostname=AUMEL11XB30CN02.biller.com] Queued mail for delivery
050 <Prod@mycomp.com>... Sent (<201704270941.v3R9fCOO014990@mymac.com> [InternalId=57724360464094, Hostname=AUMEL11XB30CN02.biller.com] Queued mail for delivery)
250 2.0.0 v3R9fCHm014995 Message accepted for delivery
Prod@mycomp.com... Sent (v3R9fCHm014995 Message accepted for delivery)

The only think i i can suspect is the difference at point 4.

Also, both the successful run and failed run say this >
Quote:
. Sent (XXXXXXXXX Message accepted for delivery
Which makes me believe that the email may have been sent in both the cases but would have been blocked due to spam as @RudiC pointed.

I can paste the entire debug of a failed run if that helps ...

Last edited by mohtashims; 04-27-2017 at 07:49 AM..
# 5  
Old 04-27-2017
Quote:
Originally Posted by mohtashims
Can you tell me where can i find those mail logs for Solaris ?
.
.
.
Can't tell for solaris, but chances are they're in /var/log/. You may refer to the syslog conf file.
# 6  
Old 04-27-2017
I don't see a To: address anywhere. Perhaps it would be better to post (as two blocks) the output generated in a working case and a failing case. Perhaps with the full flow more obvious we can see what there is.

I'm assuming that you have a mail-relay defined for sendmail to pass this on to. What do the logs there say?




Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need little script to send out email

Hi Scripters, good day. bash-4.2# df -g /apps/prd Filesystem GB blocks Free %Used Iused %Iused Mounted on /dev/xxx 64.00 4.35 94% 1269284 8% /xxx bash-4.2# I was wondering if there is a script when the usage of the mountpoint above hit 98%, email would be... (3 Replies)
Discussion started by: jaapar
3 Replies

2. Shell Programming and Scripting

Script to send email if count is >1

i have below code to count number of rows in file1.txt, if the row count is more than one then i have sending an email along with file1.txt attached and fail the process(do nothing if count is <=1), if I test individually count part works good but when i include the email part its not working,... (4 Replies)
Discussion started by: srini_106
4 Replies

3. Shell Programming and Scripting

Help with shell script to send email once

Hi Guys, I have this script which will monitor oracle db process if up or down.And I want it to send email if it's down and the time it's back to online. However my script just keep on sending "Email Up" if the db is up or "Email Down" if the db is down.Is there any way to trap it so that it... (5 Replies)
Discussion started by: d3xt3r
5 Replies

4. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

5. Shell Programming and Scripting

How to send email through shell script

Hi All, I am new to the unix , i have to deliver one script very urgently I have to write a shell script where i have i want to send email to specific email id in this script i want FROM to be parameterized and stored in a variable TO to be parameterized and stored in a variable... (3 Replies)
Discussion started by: nileshbhawsar
3 Replies

6. Shell Programming and Scripting

send an email of script output

Hi All, I'm trying to send some file which generated by script to my email. when I run the script I'm getting an email. Thats fine. But it seems to be all messed up like below Memory Status on ServerA: Mem: 3867444k total, 862680k used, 3004764k free, 54456k buffers!! CPU Status on ServerA:... (4 Replies)
Discussion started by: s_linux
4 Replies

7. Shell Programming and Scripting

Send email on script error

I need to start off by saying that I am not much of a programmer and know enough to cause lots of trouble. I've been writing this script to decrypt an XML feed, then parse the feed into a database. The script is executed from cron. #!/bin/sh PGPPATH=/path/to/directory echo "pgp... (6 Replies)
Discussion started by: Aslan_Eident
6 Replies

8. Shell Programming and Scripting

Running script that sends an html formatted email fails when its run as cronjob

Hi Im very new at working with unix and this problem I simply can not understand. I know there are a lot of threads about problems with shell scripts behaving differently when run from a terminal and from a cronjob. I have tried everything(almost) but I still havent cracked this problem. Im... (15 Replies)
Discussion started by: Nightowl
15 Replies

9. Shell Programming and Scripting

script to send a file in email

a file is created on a daily basis in the name xyz_pqr_20071207.dat.i want to send the file as an attachment if the file contains more than 50 records.how can i write a script such that it will transmit the file after the file is created.i want to sed the file to say asdf@xyz.com. please help me... (2 Replies)
Discussion started by: dr46014
2 Replies

10. Shell Programming and Scripting

script that will send and email attachment

I'm looking for a sample of some code that will take the output from a file and generate an email that will include that text as an attachment. the script is in the borne shell. any help? (2 Replies)
Discussion started by: davels
2 Replies
Login or Register to Ask a Question