Find the answer to your Linux question:
Results 1 to 4 of 4
Hey guys, I have a bit of an issue with this script: Code: MAILDIR="/var/spool/mail/lastname.firstname" TEXT="Re:" DESTDIR="~/Mail/DestFolder" find "$MAILDIR" -type f | while read N #This will find my Mail and ...
  1. #1
    Just Joined!
    Join Date
    Nov 2008
    Posts
    3

    Strange Problem

    Hey guys,

    I have a bit of an issue with this script:

    Code:
    MAILDIR="/var/spool/mail/lastname.firstname"
    TEXT="Re:"
    DESTDIR="~/Mail/DestFolder"
    
    
    find "$MAILDIR" -type f | while read N   #This will find my Mail and read it
                                             #But to do that read needs a varaible.
    do                                       #Begin the body of the while loop
           cat "$N" | grep -q "$TEXT"        #Using N as the location of my mail
           if [ $? == 0 ]; then              #If my text is matched at least once
               mv "$N" "$DESTDIR"            #Move my inbox mail int my mail folder
           fi                                #end my if statement with fi
    
    done                                     #end while
    I have no idea what is wrong. The Paths are correct. The commands seem to be ok.


  2. #2
    Just Joined!
    Join Date
    Nov 2008
    Posts
    3
    one of the possibilites could be the find command and the type that im specifying. I should prolly be looking at the Mail level and not the file level.

    Having a very hard time with this

  3. #3
    Linux Guru smolloy's Avatar
    Join Date
    Apr 2005
    Location
    CA, but from N.Ireland
    Posts
    2,413
    I know I'm really showing my ignorance with this question, but do you need the quotes around each of the variables?
    Registered Linux user #388328 || Registered LFS user #15880
    AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
    Need instant help? Try us on IRC -- #linuxforums on freenode

  4. #4
    Just Joined!
    Join Date
    Nov 2008
    Posts
    3
    I took another approach because i knew what was happening.

    If a single occurence of "whatever i had" is found by grep it will move EVERYTHING to the specifed directory.

    This is a better approach taken by me accompanied by another:

    Code:
    #!/bin/bash
    
    cat mbox | sed -r 's/From /END====From /' | sed -n 'H; ${g;s/\n/+=+/g;p}' |\
    sed 's/END====From/END\nFrom /g' |\
    egrep ".*Subject: Hello.*" |\
    sed 's/+=+/\n/g' > ~/Mail/Destdir

    exstatic.

    On the other hand. A way that i can simplfy is to create the three golden files, ".forward , .promailrc , general.rc ".
    Also:

    I have three files, .forward ( in home ) .procmailrc and general.rc ( in my .procmail directory ) And im wondering if i can get my general.rc file to do the same thing as the above code. My general.rc looks like this:

    Code:
    :0
    * ^From:.*sumone@sumaddy.com
    * ^Subject:.*hello
    $HOME/Mail/Hello
    What i think that file does is it looks for who the mail is from, whether or not hello is in the subject line and puts what it found into a Hello folder.

    So my .forward looks like this:

    Code:
    "|IFS=' '&&exec usr/bin/procmail||exit 75 #username"
    Now the most important file .procmailrc that ties everything together is as follows:


    Code:
    VERBOSE=off
    MAILDIR=$HOME/Mail
    PMDIR=$HOME/.procmail
    DEFAULT=/var/spool/mail/username
    LOGFILE=$PMDIR/log
    INCLUDERC=$PMDIR/general.rc
    #end of .procmailrc
    All three of these files work together to do the same task as the sed command script. And i know the problem might be with the general.rc i heard the grep and sed are built in?

    Any help ios appreciated!

Posting Permissions

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