Can a script automatically read mail?

Can a script automatically read mail?

Post by Josh Blo » Sun, 05 May 1996 04:00:00



Hello,
I am trying to write a bourne shell script that can automatically read mail
that is sent to it. The idea here is that the shell script is going to run as
a daemon in the backround, it will read all the mail that comes to its owner.
If the mail contains certain commands the script will react appropriately.

I can get a script to send mail, and to ftp. But I don' know how to get a
script to read mail. Can anyone tell me how unix bourne shell script can read
it's owner's mail?

I am looking for code that would be portable to all unix platforms, but for
now I am most interested in sunos and solaris.

Thanks in Advance,
josh

 
 
 

Can a script automatically read mail?

Post by mar.. » Sun, 05 May 1996 04:00:00



Quote:

>Hello,
>I am trying to write a bourne shell script that can automatically read mail
>that is sent to it. The idea here is that the shell script is going to run as
>a daemon in the backround, it will read all the mail that comes to its owner.
>If the mail contains certain commands the script will react appropriately.

>I can get a script to send mail, and to ftp. But I don' know how to get a
>script to read mail. Can anyone tell me how unix bourne shell script can read
>it's owner's mail?

>I am looking for code that would be portable to all unix platforms, but for
>now I am most interested in sunos and solaris.

In the account owner's home dir put a file called ".forward", and in
it something along the lines of:

|/usr/my_home_dir/my_script

Your script will read the mail on STDIN. If it sends mail back based
on what it gets, just make sure it ignores mail from your own account,
or MAILER-DAEMON. Your biggest concerns should be i) avoiding mail loops,
and ii) if you want other mail to your account to wind up in your normal
mbox, your script has to discern this and append the message to your
/var/spool/mail/you without clobbering or otherwise mangling your
unread mail.

(Let me reread this a few times and see what I'll get roasted for on
this one. Hmmm. All straight of my own past experiences, but I'm
sure something in here makes me look like an idiot to all these
GURU's, oh well)

--
|||| mark jeftovic              |||||  http://www.shmooze.net/~markjr     ||||
|||| p r i v a t e    w o r l d |||||        "Live Wild or Die"           ||||
------------------------------------------------------------------------------


 
 
 

Can a script automatically read mail?

Post by balthaza » Sun, 05 May 1996 04:00:00



 >Hello,
 >I am trying to write a bourne shell script that can automatically read mail
 >that is sent to it. The idea here is that the shell script is going to run as
 >a daemon in the backround, it will read all the mail that comes to its owner.
 >If the mail contains certain commands the script will react appropriately.
 >
 >I can get a script to send mail, and to ftp. But I don' know how to get a
 >script to read mail. Can anyone tell me how unix bourne shell script can read
 >it's owner's mail?
 >
 >I am looking for code that would be portable to all unix platforms, but for
 >now I am most interested in sunos and solaris.
 >
 >Thanks in Advance,
 >josh

Try reading the file where the mail is spooled. You should be able to
read the file belonging to your account.
--

       "The only way to rid oneself of"
       "temptation is to yield to it"

 
 
 

Can a script automatically read mail?

Post by era erikss » Mon, 06 May 1996 04:00:00



comp.unix.shell:
 > I am trying to write a bourne shell script that can automatically read mail
 > that is sent to it. The idea here is that the shell script is going to run as
 > a daemon in the backround, it will read all the mail that comes to its owner.
 > If the mail contains certain commands the script will react appropriately.

Get Procmail.
  <ftp://ftp.informatik.rwth-aachen.de/pub/packages/procmail/>

Hope this helps,
--

/* era */

--
See <http://www.ling.helsinki.fi/~reriksso/> for mantra, disclaimer, etc.

 
 
 

Can a script automatically read mail?

Post by Roger Denhol » Wed, 08 May 1996 04:00:00




>>Hello,
>>I am trying to write a bourne shell script that can automatically read mail
>>that is sent to it. The idea here is that the shell script is going to run as
>>a daemon in the backround, it will read all the mail that comes to its owner.
>>If the mail contains certain commands the script will react appropriately.

snip

on HPUX 10.01 I ran inside a script a line
mail < mail.script > mail.out
which read the mail to determine how a task from cron had run.  
Mail.script was

w filename
q

Note there was at least one blank line after the q command.  The script could
then parse filename to do something.
Caveat.  Any other mail can contain the required words.  You may also lose
mail you want.  I used a dummy userid to prevent this.  I also
redirected stdout/stderr to a log file eventually to avoid the
need for mail.
--

I do not speak for any Australian Govt department or body, including my own
-----BEGIN GEEK CODE-----
GAT d +s+:+ a+ C++++ UHA++++$ P+ L !E--- W+ N++ o-- K- w !O M V---
PS+ PE Y+ PGP-- t+ !5 X-- !R tv- b++ !DI !D G e h--- r+++ y++++
------END GEEK CODE------

 
 
 

1. Mail problem because a perl script reads /var/spool/mail/login?

Hi,

I wrote a short application to replace Xbiff. Basically, I wanted
something that shows a short summary of incoming mails, ignoring thus
whose sender matches a given expression (so that I dont get alarmed by
my own bcc: copies), etc. Anyway. Finally it's a perl script that
parses my /var/spool/mail/fleuret on a regular basis.

Everything seems to go smooth except that from time to time I do miss
mails. When I check the /var/log/maillog, I can see that sendmail
received the mail and did not log any error, but I dont have any trace
in my /var/spool/mail/fleuret.

The sendmail deamon runs on a SOLARIS box, and the /var/spool/mail is
mounted by nfs on my linux box. Each 15s, my script opens the mail
file with open(MAILFILE, "< $mailfile"), parses it, and closes it.

So, can there be a sort of "lock" if the file is opened for reading
and thus the sendmail can not write anything in it (I checked that and
it does not seem to lock anything)?

Any idea?

Regards,

F.

2. Connect to freebsd.org problem

3. How to read mail automatically and extracted data into database

4. rename before close

5. How do I delete mail from mail file /var/mail/su after reading mails

6. libc upgrade

7. How to get mail to log outgoing mail in folders automatically

8. lilo startup fault

9. Is there a mail program that can read mail (as root) from /var/spool/mail/xxx?

10. poppy-1.0 - simple Perl script to read/delete/save POP3 mail

11. Script reading mail and post it to HTML-Page??

12. script to read mail

13. Reading mail from shell script