Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Check the email by sh shell script

Posted on 1997-12-01
6
Medium Priority
?
669 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Suggested Courses

610 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