Click to See Complete Forum and Search --> : Sending email via bash script


Stuka
06-29-2001, 05:36 PM
What components would I need on a system to have a bash script (running as a cron job) fire off an email upon successful completion, and does anyone have an example of the process?

TheLinuxDuck
06-29-2001, 05:41 PM
As long as the system is already set up to handle email (via sendmail and the like) then it should be as simple as:


#!/bin/bash

# do this
# do that
# fwah.. fwah..

echo "process complete" > __tEmP-FiLe__
mail emailaddy@domain.ext -s "subject line" < __tEmP-FiLe__
rm __tEmP-FiLe__


I do this very thing for emailing me log parsing results on our office server. Works quite nicely. (^=

jemfinch
06-29-2001, 05:59 PM
You can also just do this:

[code]
echo <text> | mail address@domain.tld
[/quote]

Jeremy

lsibn
06-30-2001, 08:29 AM
Personally, I like an approach that doesn't have temp files:

#! /bin/bash

[...]

mail myself@somewhere -s "my subject here"<< END
My message here. You can make this as long as you want, and the message end is the text END on a line by itself. You can change this behavior by changing the text after the << redirection operator.
END

Edit: Oh, and this lets you put blank lines and other carriage returns in the messag which normally you wouldn't have. If you prefer to send a text file, you can do that to: mail myself -s "subject" < text.asc

[ 30 June 2001: Message edited by: lsibn ]

Stuka
07-01-2001, 12:03 AM
TLD-
You hit the core of my question. Is sendmail the only thing I would need to have set up properly? Or does "the like" include other items? I've never had the {joy|privilege|honor|nightmare} of setting up a system to send email.

TIA,
Stuka