Subject: Re: Q: Recipes that depend on external conditions?

From: [email-masked] (David W. Tamkin)
Date: Mon, 29 Aug 1994 13:58:55 -0500 (CDT)

Martin Zurn asked,

| Imagine the following scenario:
| I receive my mail on computer 1
| I work usually on computer 2, however, computer 2 is disconnected
| from the network.
|
| I have written a recipe that send a message to computer 2
| that works fine if both machines are up.
|
| However, whenever computer 2 is down errors occur.
| For computer 1 it would be easy to define a variable that checks whether
| or not computer 2 is down.
| However, I do not know how I could use such a variable in the recipe
| file. Do you know?

It's fairly straightforward.  Here are some examples:

First, suppose the variable contains "up" if the other computer is up but
"down" when it is down:

  :
  * ? test "$variable" = up
  ! martin@computer2

(For some strange reason I like to use '[ ]' in shell scripts but the word
'test' in procmail recipes.)

Alternatively, let's say the variable is null or unset if computer 2 is down
but contains some text if computer 2 is up:

  :
  * $${variable:+!}!
  ! martin@computer2

Or say computer 1 finds out whether computer 2 is up by running a program and
getting its exitcode: 0 if computer 2 is up, nonzero otherwise:

  :
  * ? program_to_see_if_a_machine_is_up computer2
  ! martin@computer2

David W. Tamkin  P. O. Box 3284  Skokie IL  60076-6284
[email-masked]   MCI Mail: 426-1818   +1 312 714 5610

---

From: Roman Czyborra <[email-masked]>
Date: Tue, 30 Aug 1994 20:10:37 +0200

> I receive my mail on computer 1 I work usually on computer 2,
> however, computer 2 is disconnected from the network.  I have
> written a recipe that send a message to computer 2 that works fine
> if both machines are up.

I'm not sure I understand how you want to contact a disconnected
computer to begin with.

> However, whenever computer 2 is down errors occur.

How come?  Normally sendmail should queue the copy for computer2.
How exactly are you trying to transport the message?

> For computer 1 it would be easy to define a variable that checks
> whether or not computer 2 is down.  However, I do not know how I
> could use such a variable in the recipe file.

If it is so easy to keep a variable up-to-date, it should not be much
harder to change your .procmailrc or an INCLUDERC to turn the
forwarding on or off for every announced change in the state of
computer2.

> In other words: How to create recipes that depend on external
> conditions (e.g. given by shell variables)? (not on internal
> conditions that depend on the incoming mail itself)

David's already told you how to branch on different variable settings.

Just keep in mind that shell variables are local to the shell and
environment variables are inherited by its children only.  Your
procmail will be called from the mail server and not from your shell.
Plus your shell will only be up as long as you're logged on.  So,
there will neither be an easy way for procmail to query your shell's
variables nor for the shell to manipulate procmail's environment.

To test external conditions for incoming mails you can either read in
status files or call programs and use their exit code.  Your problem
might be solved as follows

	:c
	? /usr/etc/ping computer2 1 1
	! martin@computer2