Solved

Check the email by sh shell script

Posted on 1997-12-01
6
592 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
6 Comments
 
LVL 2

Author Comment

by:clo1
Comment Utility
Edited text of question
0
 
LVL 2

Expert Comment

by:df020797
Comment Utility
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
Comment Utility
I can pretty sure a sh shell script can do this task. Please help
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Expert Comment

by:dhughes111797
Comment Utility
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 50 total points
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now