[comp.unix.questions] q: being notified of new mail

garyo@wdl1.UUCP (gary ogasawara) (10/26/87)

What do I have to do so that when new mail arrives, I am interrupted
and a message is displayed on my window?  Right now, I don't know if
new mail has arrived unless I type "mail".  Thanks,
gary

chris@mimsy.UUCP (Chris Torek) (10/27/87)

In article <4350001@wdl1.UUCP> garyo@wdl1.UUCP (gary ogasawara) writes:
>What do I have to do so that when new mail arrives, I am interrupted
>and a message is displayed on my window?

On a 4BSD-based system, say `biff y'.  This has the unfortunate (to
me at least) effect of, when you least expect it, blatting on top of
something you were trying to read.

In (some?) C shells, you can set a variable called `mail' that tells
the shell to announce new mail before printing a prompt:

	set mail = /usr/spool/mail/$user

or

	set mail = (600 /usr/spool/mail/$user)

The second form instructs csh to check only once every 600 seconds
(10 minutes).  This is also the default.  To make it check more often,
use a smaller number.  In any case, csh checks only immediately before
printing a prompt.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris

gwyn@brl-smoke.UUCP (10/30/87)

In article <4350001@wdl1.UUCP> garyo@wdl1.UUCP (gary ogasawara) writes:
>What do I have to do so that when new mail arrives, I am interrupted
>and a message is displayed on my window?

Short of running "sysmon" on your Blit/DMD/MTG, the best solution is
probably to use the MAIL or MAILPATH features of the Bourne shell,
if your version supports it.  Some systems also provide a "biff"
utility, or "fido", or some other such program that runs in the
background and can be instructed to blather on your terminal when
your mailbox changes, if you really want that (it messes up your
display if you're text-editing).  Look in your manual to see if
your system supports any of these methods; it will give further
details.

irf@kuling.UUCP (10/30/87)

In article <9111@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes:
>In article <4350001@wdl1.UUCP> garyo@wdl1.UUCP (gary ogasawara) writes:
>>What do I have to do so that when new mail arrives, I am interrupted
>>and a message is displayed on my window?
>In (some?) C shells, you can set a variable called `mail' that tells
>the shell to announce new mail before printing a prompt:
>	set mail = /usr/spool/mail/$user
>or
>	set mail = (600 /usr/spool/mail/$user)

In HP-UX I write

        set mail = (60 /usr/mail/$LOGNAME /etc/motd)

and get notified if, within the last 60 seconds, there is new mail
for me or if there is a new "message-of-the-day" (motd).


:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Bo Thide', Swedish Institute of Space Physics. UUCP: ...enea!kuling!irfu!bt
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

marki@hpiacla.HP.COM (Mark Ikemoto) (11/21/87)

>In HP-UX I write
>
>        set mail = (60 /usr/mail/$LOGNAME /etc/motd)
>
>and get notified if, within the last 60 seconds, there is new mail
>for me or if there is a new "message-of-the-day" (motd).

How did you get this to work?  I've tried it on my 9000/350 and it
doesn't notify me.  I had to create a shell script that I run in the
background at the start of my session to check for mail periodically.

-----------------

If anyone out there is interested in getting a copy of this shell
script (it is documented profusely internally and has error-checking),
send me a message.


Mark

ccoprrd@pyr.gatech.EDU (Richard Dervan) (11/22/87)

Well, the 'biff' command also works.  In your .login or .profile,
try:
biff y
That should arrive you when mail arrives.  The only thing is that it will
even tell you if you're in vi or something like that.  The thing about it
is that it will tell you who the mail is from in addition to just saying
"Hey!  You got some new mail!"

-- 
Richard Dervan - Office of Computing Services
Georgia Insitute of Technology, Atlanta Georgia, 30332
uucp: ...!{akgua,allegra,amd,hplabs,ihnp4,seismo,ut-ngp}!gatech!gitpyr!ccoprrd
ARPA: ccoprrd@pyr.ocs.gatech.edu

irf@kuling.UUCP (Stellan Bergman) (11/27/87)

In article <3600001@hpiacla.HP.COM> marki@hpiacla.HP.COM (Mark Ikemoto) writes:
>>In HP-UX I write
>>
>>        set mail = (60 /usr/mail/$LOGNAME /etc/motd)
>>
>>and get notified if, within the last 60 seconds, there is new mail
>>for me or if there is a new "message-of-the-day" (motd).
>
>How did you get this to work?  I've tried it on my 9000/350 and it
>doesn't notify me.  I had to create a shell script that I run in the


Oh yes, I'm positive.  Whenever mail arrives I get a friendly little message
saying "You have mail" as soon as I leave whatever I'm doing and get back
to the (C) shell.

This is how my .login file on our HP9000/500 HP-UX 5.21 looks like (also
worked OK for HP-UX 5.11):

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

# Fix the tty line
stty -ienqak ixon -ixoff

# Set up termcap, terminal, and EXINIT
set noglob; eval `tset -sm 'chal:?chal' -sm 'vt100:?vt100' -sm 'go250:?go250' -sm 'go250-sm:?go250-sm' -sm 'go250-48:?go250-48' -sm '2382:?2382'`

switch ( $TERM )

  (Uninteresting terminal setups here ...)

endsw
source .EXINIT                                # Terminal independent EXINIT.
source .EXINIT_$term                          # Terminal specific EXINIT.
echo "EXINIT set for $term"                   # To see we got it right...
source $home/.envrc                           # Load environment parameters.
source $home/.aliasrc                         # Load useful aliases.
setenv PROMPT '>'                             # Use this instead of PS1.
set userprompt="$SMSO(`whoami`)\!$PROMPT$SGR0"# Make a nice prompt.
set CWD="$TSL$REV$cwd$SGR0$FSL"               # Put cwd in the status line
set prompt="$userprompt$CWD "                 # Set the prompt and write cwd.
set autologout=0                              # Logout? Never.
mv $HOME/.history $TEMPDIR                    # Move original .history file.
sort $TEMPDIR/.history|uniq >! $HOME/.history # Remove duplicates and move back.
/bin/rm -f $TEMPDIR/.history                  # Remove temporary .history file.
set history=100                               # Save last 100 cmds in a stack.
set savehist=100                              # Save last 100 cmds in a file.
set mail = (60 /usr/mail/$LOGNAME /etc/motd)  # Any mail/motd last minute?
clear                                         # Start with a nice, clean screen.
calendar                                      # Any appointments?
umsk 022                                     # S my friends cannot write.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Bo Thide', Swedish Institute of Space Physics.  UUCP: ..enea!kuling!irfu!bt
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

dave@lsuc.UUCP (12/03/87)

In article <4516@pyr.gatech.EDU> ccoprrd@pyr.gatech.EDU (Richard Dervan) writes:
>Well, the 'biff' command also works.  In your .login or .profile,
>try:
>biff y
>That should arrive you when mail arrives.  The only thing is that it will
>even tell you if you're in vi or something like that.  The thing about it
>is that it will tell you who the mail is from in addition to just saying
>"Hey!  You got some new mail!"

If you can't use biff(1) because your mail isn't a BSD mpx file, but
you do have access to BSD utilities source, then tra(1) works
just as well -- even better, to my mind, since it spits out
the entire mail message, not just the first couple of lines.
I have a "tra - $MAIL &; trap "kill $!" 0" in my .profile, so
that mail to me ALWAYS gets to my screen right away.  You
learn to use the ctrl-L key to redraw your rn, more or
whatever screen, that's all.  If you get lots of mail, as
I do, seeing it right away is valuable.

tra has two bugs as distributed, as applied to this use: its
default run-time is 32767 seconds, which is too short if you
leave it running all day; and it doesn't seek back to the end
if your mail file gets shorter (when you read and dispose of
your mail). Both are easy to fix; I can send the changes if
anyone wants them.

If you don't have tra(1) but have good C programming skills,
you can probably write it in 10 minutes.  It just sits and
watches a file's size, displaying anything that's been added
to the file's tail every time it grows.  The '-' argument
suppresses printing of what's in the file at the time tra
starts up.

David Sherman
The Law Society of Upper Canada
Toronto
-- 
{ uunet!mnetor  pyramid!utai  decvax!utcsri  ihnp4!utzoo } !lsuc!dave
Pronounce it ell-ess-you-see, please...

eap@bucsb.UUCP (Eric Pearce) (12/04/87)

In article <1987Dec3.000951.15189@lsuc.uucp> dave@lsuc.UUCP (David Sherman) writes:
>In article <4516@pyr.gatech.EDU> ccoprrd@pyr.gatech.EDU (Richard Dervan) writes:
>>Well, the 'biff' command also works.  In your .login or .profile,
>>That should arrive you when mail arrives.  The only thing is that it will
>>even tell you if you're in vi or something like that.  The thing about it
>>is that it will tell you who the mail is from in addition to just saying
>>"Hey!  You got some new mail!"
>
>If you don't have tra(1) but have good C programming skills,
>you can probably write it in 10 minutes.  It just sits and
>watches a file's size, displaying anything that's been added
>to the file's tail every time it grows.  

I wrote something of this sort as a part of another program.  Somebody might
find this useful, so here it is.

#include <stdio.h>
#include <sys/types.h> 
#include <sys/stat.h>
#define MAILFILE "/usr/spool/mail/yourname"
#define SLEEP 30
main()
{ 
 struct stat st;
 char path[50];
 int old_size=0,new_size=0;

 while(1) {   
    old_size = new_size;
    if (!stat(sprintf(path, "%s", MAILFILE), &st)) 
      new_size = st.st_size;
    if (old_size < new_size) fprintf(stderr,"You have new mail.\n"); 
    sleep(SLEEP);
 }
}

Actually displaying the new mail seems like something best left to your mail
program, but that's just an opinion ...

                                                         -eap
-- 
**** .signature reduced in length due to space considerations *****************
| UUCP   : ..!harvard!bu-cs!bucsb!eap     |        ARPANET: eap@bucsb.bu.edu  |
| CSNET  : eap%bucsb@bu-cs                |        BITNET : cscc8vc@bostonu   |

amos@taux01.UUCP (Amos Shapir) (12/06/87)

While we are at it: you don't even need a special program to do that -
I'm using a shell file that keeps the output of 'wc' in a sh variable,
and may use it as an argument to 'tail' if the contents of the watched
file are wanted. (Implementation is left as an exercise to the reader).
-- 
	Amos Shapir			(My other cpu is a NS32532)
National Semiconductor (Israel)
6 Maskit st. P.O.B. 3007, Herzlia 46104, Israel  Tel. +972 52 522261
amos%taux01@nsc.com (used to be amos%nsta@nsc.com) 34 48 E / 32 10 N

levy@ttrdc.UUCP (Daniel R. Levy) (12/08/87)

In article <1308@bucsb.UUCP>, eap@bucsb.UUCP (Eric Pearce) writes:
#> >If you don't have tra(1) but have good C programming skills,
#> >you can probably write it in 10 minutes.  It just sits and
#> >watches a file's size, displaying anything that's been added
#> >to the file's tail every time it grows.  

Or, "tail -f /usr/mail/mylogin &" [ /usr/spool/mail/mylogin for Bezerkeloids ]

One problem with this might be if you are showing someone else something on
your terminal and a highly personal piece of mail arrives, that might not be
too cool.  Also, it would mess up graphics in graphics-oriented programs and
might even hang the terminal (I'm talking about like TEK tube graphics).
-- 
|------------Dan Levy------------|  Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa,
|         an Engihacker @        |  	<most AT&T machines>}!ttrdc!ttrda!levy
| AT&T Computer Systems Division |  Disclaimer?  Huh?  What disclaimer???
|--------Skokie, Illinois--------|