?
Solved

Check the email by sh shell script

Posted on 1997-12-01
6
Medium Priority
?
659 Views
Last Modified: 2013-12-26
I would like to have a sh shell script to do the following:

I want to check my email for certain time period, say 60 sec. to see I have received any new mail during that period. I also want to have 3 options :

1. An option that allows me to use the prog to check any    user on the same system, to see if this user has    received any new mail during that period.

2. An option that allows me to control the length of the    time period.

3. An option that allows me to decide how to be informed,    by email of message.
0
Comment
Question by:clo1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Author Comment

by:clo1
ID: 1295710
Edited text of question
0
 
LVL 2

Expert Comment

by:df020797
ID: 1295711
One way is to check the atime for the mailfiles you want to check. This though takes a C program, cant be done in a sh script. The part when you want a biff function for your own mail, its doable... but why invent something already done... there are thousands of mailbiff:S

0
 
LVL 2

Author Comment

by:clo1
ID: 1295712
I can pretty sure a sh shell script can do this task. Please help
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:dhughes111797
ID: 1295713
use ls -lu to get time of last access on a mailbox
(when last read)
regular ls -l will show time of last modification (last write)
0
 
LVL 2

Accepted Solution

by:
lockhart earned 200 total points
ID: 1295714
You can do it easiest by checking the size of the mail file and using that as your trigger. So something like this would be a good first step.

#!/bin/sh
cd /var/mail
user=`/usr/ucb/whoami`             # or wherever your whoami is
                                   # could use an env vbl
# get your command line options
set -- `getopt u:t:m: $*`
if [ $? != 0 ]; then
    echo $USAGE
    exit 2
fi
for ii in $*; do
    case $ii in
    -u) user=$2; shift;;
    -t) time=$2; shift;;
    -m) method=$2; shift;;
    --) shift; break;;
    esac
done

last_size=0                      # so you'll know if it has mail
                                 # to start
while true
do
   current_size=`ls -l | grep $user | nawk '{print $5}'`
   if [ $last_size -lt $current_size ]; then
       
       echo $user " has mail"    # or trigger something based on
                                 # $method
   else
       echo no mail yet
   fi
   last_size=$current_size
   sleep $time
done

This assumes that the fifth field (space separated) from an ls -l command is the file size. This does most of what you wnat. You can put the stuff in to notify yourself however you want. On solaris there's a nifty program called play that plays sounds that can be fun (especially if you rsh it on someone else's machine and have it play a bunch of stuff ;)

Mike
0
 
LVL 2

Expert Comment

by:lockhart
ID: 1295715
PS - I forgot to init the time and method variables. They should be done before the getopts segment so that you can over-ride the default values like with the user variable. I hate the way their font screws up the comments, they were all in the 32nd column.

Mike
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question