Unix : Script that sends a file via mailx

I am supposed to write a script that sends a file (using mailx), that I created, to my professor. This is a killer, I can't seem to figure out how to solve this problem.

Additionally, if anybody could let me know how to include the date (using the date command) on the subject line that would be great.

I put the date in back quotes. (see below)

$ mailx username@yahoo.com
Subject: `date +"%d-%m-%Y %R"`
.
EOT

but it arrives in my subject line exactly as printed above.

Subject: `date +"%d-%m-%Y %R"`

-----------------------------/

Try putting this within your script.
Echo the body of your messeage to /usr/ucb/Mail.
echo "Body of Message" | /usr/ucb/Mail -s "`date +%d-%m-%Y %R`" username@yahoo.com

You can also put a list of names in a file (/nitely/maillist). Then replace the <username@yahoo> with (and remember the back quotes) `cat /nitely/maillist`

-----------------------------/

If you can use ksh, $(expr) is better than `expr`.

Expressions like this can only be evaluated by the shell, not within applications.

mailx -s $(date)

etc should work.

I don't have mailx to test right now, but you could try something like

mailx -s $(date) < yourfile.txt

-----------------------------/

Any shell script that automatically mails the desired address. What are the required parameters necessary to write such a script.

cat your_file | mailx -s"test" you@example.com

Or you can use this:
mail -s "Your Subject Line" you@domain.com < your_file

sendmail may also be available on your system.
Use the man pages for either to get more detail.

See Also
Unix Administrator Career Path

Have a Unix Problem
Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.