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

Empty subject when using mailx.

SOLVED
Go to solution
Adnane_1
Occasional Advisor

Empty subject when using mailx.

Hello Folks,
I getting an empty email when using the following command in a Korn shell script:

subject="Testing ..."
echo "Subject =${subject}"
mailx -s"${subject}" myemail
Anyone can help on this?

Adnane
17 REPLIES
James R. Ferguson
Acclaimed Contributor

Re: Empty subject when using mailx.

Hi Adnane:

By redirecting /dev/null to STDIN you got exactly what you asked: an empty email body.

You could redirect another file, instead, or you could type your email body message at the command line and type CNTL_D (end-of-text) to signal its end. For example:

mailx -s "Testing..." myuser
This is line-1
and this is line-2
of a three-line message


Regards!

...JRF...
Muthukumar_5
Honored Contributor

Re: Empty subject when using mailx.

Try with this,

subject="Testing..."
echo "Subject= ${subject}"

mailx -s "$subject" root@localhost mail

You will get that recent mail with Testing... as subject.

hth.
Easy to suggest when don't know about the problem!
Adnane_1
Occasional Advisor

Re: Empty subject when using mailx.

Guys,
I getting an empty subject. The /dev/null is intentional to get an empty email but why the subject is empty?


Thanks.
Muthukumar_5
Honored Contributor

Re: Empty subject when using mailx.

What you are getting with sendmail?

# subject="check..."
# echo "Subject: ${subject}" | sendmail root@localhost
# mail

hth.
Easy to suggest when don't know about the problem!
Pat Lieberg
Valued Contributor

Re: Empty subject when using mailx.

Take out the () in your mailx line. It should read:

mailx -s "$subject" myemail
Gavin Clarke
Trusted Contributor

Re: Empty subject when using mailx.

There seems to be a space missing between the -s and the "${subject}".

I also get the feeling that Pat is right and the {} need to go too.
Matthew_50
Valued Contributor

Re: Empty subject when using mailx.

Hi, Adnane,

I think the second line is not necessary, simply use

#!/bin/ksh
subject="Testing ..."
mailx -s ${subject} who@myemail.com < /dev/null
Adnane_1
Occasional Advisor

Re: Empty subject when using mailx.

Hi Folks,
I tried your suggestions and Iâ m getting the same problem (the sendmail as mention by HTH did not work for me, I think the setup for the DS entry is messing in the sendmail.cf file).
However I found out that when I submit the job my self I got the the email and the subject but when the scripts is submitted by the scheduler MAESTRO (scheduler program from IBM that runs under UNIX HP) I got the email but not the subject.

Did anyone have an idea ?



Thanks to all for your help.
Pat Lieberg
Valued Contributor

Re: Empty subject when using mailx.

It sounds to me like the $subject is not being interpretted by the script and might be interpretted by the shell, which is evaluating to nothing and therefore, no subject.

As mentioned in Matthew's post, do you have the #!/bin/ksh line at the top of your script?
Adnane_1
Occasional Advisor

Re: Empty subject when using mailx.

Hi Folks,
Yes Pat I do have #!/bin/ksh.

Just to mention that my script is working perfectly in the DEV server, the problem occur on another UNIX HP server.

Thanks.
Pat Lieberg
Valued Contributor

Re: Empty subject when using mailx.

I'm kind of at a loss what to try next, but you might look at the permissions of both the script and the /bin/ksh file.

Sorry I wasn't more help.
Rita C Workman
Honored Contributor

Re: Empty subject when using mailx.

hmmm... I just did this:

#subject=Testing...
#echo $subject

..it echo'd properly..

#mailx -s $subject rworkman@mydomain.com < /dev/null

and then I

#mail -s $subject rworkman@mydomain.com
.

...and they both went to my email reflecting a subject of ... Testing...


Yeppers...drop the {}

Rgrds,
Rita
Dave La Mar
Honored Contributor
Solution

Re: Empty subject when using mailx.

Adnane-
Though I feel your question on the blank subject has been answered, I am attaching a list of different uses of mailx that are used in out shop. Should you still be having a problem, try an example from that attached.

Best of luck.

Regards,

dl
"I'm not dumb. I just have a command of thoroughly useless information."
Adnane_1
Occasional Advisor

Re: Empty subject when using mailx.

Thanks to all of you.

I removed the /dev/null because it seems causing the problem in the subject.

Now I'm using the mailx command :

echo "$EMAIL_SUBJ" | mailx -s"$EMAIL_SUBJ" "$recipient"


Adnane.
Adnane_1
Occasional Advisor

Re: Empty subject when using mailx.

Removed the /dev/null

and using the mailx command as:

echo "$EMAIL_SUBJ" | mailx -s"$EMAIL_SUBJ" "$recipient"
Muthukumar_5
Honored Contributor

Re: Empty subject when using mailx.

Which mailx version you are using. I have tried with /dev/null it is working for me. Ok. You are decided to leave /dev/null. ;) It is not needed at all.

hth.
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: Empty subject when using mailx.

Adnane,

I hope you are a new number. Try to assin points to those spent time with you. Hope you know the way to give points.

thx.
Easy to suggest when don't know about the problem!