Find the answer to your Linux question:
Results 1 to 9 of 9
Hello All, I am trying to write a script which will check and informed user that there is a new email. Is any one tell me, how can i find ...
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Posts
    17

    How to check whether there is new email or not

    Hello All,

    I am trying to write a script which will check and informed user that there is a new email. Is any one tell me, how can i find that?

    Thanking You,

  2. #2
    oz
    oz is online now
    forum.guy
    Join Date
    May 2004
    Location
    arch linux
    Posts
    18,099
    Hello

    Take a look at mailcheck:

    mailcheck

    It should be able to handle the task of checking mail for you, and other options are available online.
    oz

    new members/users: read this first | new member faq
    no private messages requesting computer support - post them on the forums!
    please use the "report post" button to alert our forum admins to problematic posts rather than responding to them yourself.

  3. #3
    Just Joined!
    Join Date
    Oct 2011
    Posts
    17
    Please check my code is as follow



    Code:
    
    
     while true
            do
                    mail -E
                    stat=`echo $status`
                    echo $stat
                    if [  "$stat" -eq 0 ]
                    then
                            echo There is new e-Mail to read.
                            exit 1
                    else
                            echo No new e-Mail.
                            sleep 30
                            continue
                    fi
            done


    It's everytime saying that you have new mail. Infact there is no email.

  4. #4
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    Perhaps this will help:
    Exit status $?
    Code:
           ?      Expands to the status of the most recently executed foreground
                  pipeline.
    
    -- excerpt from man bash
    As far as I know, $status is for the csh-family shells.

    Bet wishes ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  5. #5
    Just Joined!
    Join Date
    Oct 2011
    Posts
    17
    No, it's not working either.

  6. #6
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    Saying it does not work and similar responses is not useful.

    If you have changed your code, post it, along with results. If you are getting an error message, post it verbatim ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  7. #7
    Just Joined!
    Join Date
    Oct 2011
    Posts
    17
    I was getting error "test: unknown operator 0", but I have resolved it. Now I have some other problem. It is always saying you have new email eventhough there is no email (empty) in mailbox. Please have look my code as follow:

    Code:
    #!/usr/bin/sh
    
    # Program to check whether a new email during 30 seconds or not
    
            while true
            do
                    mail -E
                    echo $?
                    if [ "echo $?" -gt "0" ]
                    then
                            echo There is no e-Mail to read.
                            sleep 30
                            continue 1
                    else
                            echo You have new e-Mail.
                            exit 1
                    fi
            done
    [output]
    1
    You have new e-Mail.

    [/output]

  8. #8
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    This script describes the computing environment, then shows how to test the result of an operation, both with failure and success:
    Code:
    #!/usr/bin/env bash
    
    # @(#) s1	Demonstrate exit status and checking.
    
    # Utility functions: print-as-echo, print-line-with-visual-space, debug.
    # export PATH="/usr/local/bin:/usr/bin:/bin"
    pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
    pl() { pe;pe "-----" ;pe "$*"; }
    db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
    db() { : ; }
    C=$HOME/bin/context && [ -f $C ] && $C
    
    pe
    status=$?
    pe " Initial exit status = $status"
    
    pe
    garbage
    status=$?
    pe " Status after command not found = $status"
    
    pe
    status=$?
    pe " Current status is $status"
    if [ $status -eq 0 ]
    then
      pe " Status was zero."
    fi
    
    pe
    ls no-such-file
    status=$?
    if [ $status -eq 0 ]
    then
      pe " Status was zero."
    else
      pe " Status was not zero: $status"
    fi
    
    exit 0
    producing:
    Code:
    % ./s1
    
    Environment: LC_ALL = C, LANG = C
    (Versions displayed with local utility "version")
    OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
    Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
    GNU bash 3.2.39
    
     Initial exit status = 0
    
    ./s1: line 18: garbage: command not found
     Status after command not found = 127
    
     Current status is 0
     Status was zero.
    
    ls: cannot access no-such-file: No such file or directory
     Status was not zero: 2
    I'm confident in your ability to see the similarities between my code and what yours should be.

    Remember that echo, printf and man pages are your friends.

    Best wishes ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  9. #9
    Just Joined!
    Join Date
    Oct 2011
    Posts
    17
    Hi there,

    I gotcha you, thanks for your explanation.

    Best Regards,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...