How to write a "Notice Program"

How to write a "Notice Program"

Post by Ryan Faric » Wed, 12 Jul 2000 04:00:00



I'd like to write a notice program for my internet server. I'd like to use
it to notify users when their email hasn't been checked for awhile, etc,
etc, to remind them to check it.

What I want to use is shell scripts only. I don't think I need to use Perl.
I basically just want to create email templates, with variables contained
within, that my shell script will temporarily replace and send the modified
template to the user's alternate email address.

Here is a sample template:
------------

To: $useraltemail
Subject: You haven't checked your mail for awhile

This is an automated message sent by $domainname at $ipaddress.
This message is being sent to you as it concerns your mailbox at
'faricy.net/var/spool/mail/$username'.

You have $n message(s) in your mail box. The earliest message in your box
is dated '$fdate', and the latest, '$ldate'. Your mail box
currently occupies $B byte(s), or ~$KB of space.

This is only a notice to remind you about your account at faricy.net or
one of its domains, but there is no obligation to do anything about it.

Thank you.
----------------

How can I make a shell script that will take this file, replace the
variables with values, and save those modifications to a temporary file (to
be mailed)? I do know how to mail it with sendmail, but not how to do
replace variables in a template file with values that have been inputted by
the script file. Is this even possible? I know its possible to use values
entered in the same script later, but can those values be passed to and
replaced inside a template like I want the above?

I hope you understand. Thank you!

--

Systems Administrator
http://www.faricy.net

 
 
 

How to write a "Notice Program"

Post by boug.. » Thu, 13 Jul 2000 04:00:00


Well, this is certainly not the best way, but you could use sed.
cat /tmp/foo | sed 's/$hostname/mail.foo.org/g' > /tmp/foobis

Another thing you could check out might be the macro processor m4.

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

How to write a "Notice Program"

Post by William Shott » Sat, 15 Jul 2000 04:00:00


Well, you could do something like this...

# start of script fragment

mail $useraltmail << _EOF_


To: $useraltemail
Subject: You haven't checked your mail for awhile

This is an automated message sent by $domainname at $ipaddress.
This message is being sent to you as it concerns your mailbox at
'faricy.net/var/spool/mail/$username'.

You have $n message(s) in your mail box. The earliest message in your box
is dated '$fdate', and the latest, '$ldate'. Your mail box
currently occupies $B byte(s), or ~$KB of space.

This is only a notice to remind you about your account at faricy.net or
one of its domains, but there is no obligation to do anything about it.

Thank you.
----------------

_EOF_

# end of script fragment

Everthing between the _EOF_ tokens is a "here script".  Within it you can
do all the variable substitution you like.  It will be taken as the
standard input to the "mail" command.

--

|||||  http://www.clark.net/pub/bshotts/ (Updated 04/13/2000)
|||||  Be a Linux Commander!  Follow me to http://linuxcommand.org

 
 
 

How to write a "Notice Program"

Post by Frank Ranne » Sun, 16 Jul 2000 04:00:00



> I'd like to write a notice program for my internet server. I'd like to use
> it to notify users when their email hasn't been checked for awhile, etc,
> etc, to remind them to check it.

> What I want to use is shell scripts only. I don't think I need to use Perl.
> I basically just want to create email templates, with variables contained
> within, that my shell script will temporarily replace and send the modified
> template to the user's alternate email address.

> Here is a sample template:
> ------------

> To: $useraltemail
> Subject: You haven't checked your mail for awhile

> This is an automated message sent by $domainname at $ipaddress.
> This message is being sent to you as it concerns your mailbox at
> 'faricy.net/var/spool/mail/$username'.

> You have $n message(s) in your mail box. The earliest message in your box
> is dated '$fdate', and the latest, '$ldate'. Your mail box
> currently occupies $B byte(s), or ~$KB of space.

> This is only a notice to remind you about your account at faricy.net or
> one of its domains, but there is no obligation to do anything about it.

> Thank you.
> ----------------

> How can I make a shell script that will take this file, replace the
> variables with values, and save those modifications to a temporary file (to
> be mailed)? I do know how to mail it with sendmail, but not how to do
> replace variables in a template file with values that have been inputted by
> the script file. Is this even possible? I know its possible to use values
> entered in the same script later, but can those values be passed to and
> replaced inside a template like I want the above?

> I hope you understand. Thank you!

> --

> Systems Administrator
> http://www.faricy.net

Shell allows you to embed a document like this:

cat <<EndText
Hello $USER
Your userid is $UID and you are using the $SHELL shell.
Today is `date`

EndText

As you can see, variables are substitued and backquoted commands are
executed.

regards, Frank Ranner