Question

I have written a shell script that will trigger a mail using sendmail command in aix . But I want the sender to by root@myhostname.com .

This is my script :

# cat mail1.sh
sendmail -t -F 'Root ' -f 'Root@`echo `hostname``.com' << test.mail
From: Root <Root@`echo `hostname`.com>
To: abc@xyz.com
Subject:Password Expiry
Hi,

Root Users's Password will expire in $1 days
Consider changing it soon.


Regards
System

I want sender to be for example root@'hostname'.com

Was it helpful?

Solution

  • Assign the values to shell variables. It makes interpolation cleaner.

  • end "here documents" (<<MXXX)

  • use -i sendmail command line option

  • separate email email headers an body with empty line

Modified script:

HOSTNAME=`hostname`
SENDER="Root@${HOSTNAME}.com"
RECIPIENT="abc@xyz.com"

sendmail -t -i -f${SENDER} <<TEST_MAIL
From: Root <${SENDER}>
To: <${RECIPIENT}>
Subject:Password Expiry

Hi,

Root Users's Password will expire in $1 days
Consider changing it soon.


Regards
System
TEST_MAIL
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top