Solved

Check the email by sh shell script

Posted on 1997-12-01
6
619 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
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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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 50 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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 49
Named range not carried over 10 63
fizzArray  challenge 1 83
wordcount challenge 11 121
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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