You are not logged in.
Pages: 1
hey guys,
I think im on the right track here:
#adr=${1:-`whoami`}
# Typing 'self-mailer.sh adr@someaddy
#cat $0 | mail -s "Feedback" "$adr" |\ ##this sends mail to me
find ~/Mail/INBOX/Hello | grep ~/Hello "^/hello" -mv Hello
#echo "At `date`, script \"`basename $0`\" mailed to "$adr"firstname.lastname"
#exit 0
But what i actually need is to get those messages from my pine inbox, and put them in a folder on my desktop.
In the script imlooking for a pattern that finds messages that contain the subject, 'Hello'
Could someone help with this?
Last edited by oxoxo (2008-11-16 17:41:21)
Offline
If I understand what you're trying to do correctly:
#!/bin/sh
MAILDIR="/home/filip/Mail/Inbox"
TEXT="Hello"
DESTDIR="/home/filip/Desktop/test"
find "$MAILDIR" -type f | while read N
do
cat "$N" | grep -q "$TEXT"
if [ $? == 0 ]; then
mv "$N" "$DESTDIR"
fi
done
This script checks all the files in MAILDIR (including subdirectories) and then checks if any of these files contains text TEXT -- if TEXT is matched then the file gets moved to DESTDIR.
Offline
Im glad that you understand. But let me be more specific.
I need to grab the mail from the Pine Inbox. I dont know of any directory that can specify that location and:
" pine -if inbox " does take me where i want to go, but it is not a path.
Offline
Hmm, I've no experience with using pine, so I'm afraid I can't help with that... But the script should work on any directory you define, so if you establish what the pine inbox directory is you should be able to just use it as $MAILDIR in the script.
Offline
Hey,
So grep found the pattern that i needed and moved those messages from my pine inbox to different folder in my mail directory. Now, for some reason, its not working.
When it did work, all i did was email myself a message that matches what you had in the script for the greps pattern. I executed the command file and it worked right away. I checked my folder and it was there. This time i did the same thing and now nothing. Very Strange.
Offline
I figured out why its not working.
When im finding my mail in my MAILDIR, im finding 'files types' specificly the -type f argument for find.
Is there a way to search my message level? Not just the file level itself.
Offline
I figured out why its not working.
When im finding my mail in my MAILDIR, im finding 'files types' specificly the -type f argument for find.
Is there a way to search my message level? Not just the file level itself.
The find command can only work with individual files -- I'm not sure what you mean by "message level"... If your mails are not in separate files then the find command is not going to be useful.
Offline
Is there a way to transform the find command? Like using grep insted or something equivalent to what you gave me?
Its not working now, so i need to try something new when searching for the messages. The path that i specified is correct so it is in fact searching the correct path.
Offline
Are you using Maildir format for your mail, or mbox format?
mbox stores all messages per folder in one file, so it will be very difficult to move one message to another folder. I'd hazard to say almost impossible to do in a script using grep and find etc
Maildir stores each message in a different file, so that will make it easier.
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
Maildir for my mail. And all my messages are in /var/spool/mail/name.lastname as seperate file names.
And from what im told is where my all my messages are stored.
Also mbox might store all the mail as one file. So im not going to worry about that.
Offline
In that case, fwojciec's script should work...?
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
Ok..i know whats happening.
What happens is if ONE FILE is named "Hello" EVERYTHING will be moved to a seperate folder in my mail directory.
Im trying now to just get the one file named "hello" in a seperate folder. NOT EVERYTHING because of ONE FILE.
Offline
A file with the same name as the string you're looking for won't be treated any differently to a file named "rumpelstiltskin"
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
No its not the same name.
If i have the files:
hello
zzzzz
Both of them will be moved.
I think it might be something to do with the control statements.
Also, in the script is there a way to turn off the case sensitivity?
I want to grab hello and Hello.
Offline
The logic of the above script is very simple.
1. find all *files* (-type f) in a given directory (MAILDIR)
2. for each file: check if it contains the given string (TEXT)
3. if and only if the file contains the specified string move the file to DESTDIR
So it doesn't matter what a file is called -- what matters is whether it is a file (not a directory or a link) and whether it contains the given string.
As far as making the script disregard the lower/upper case; something like this should work:
#!/bin/sh
MAILDIR="/home/filip/Mail/Inbox"
TEXT="Hello"
DESTDIR="/home/filip/Desktop/test"
TEXT=$(echo "$TEXT" | tr "[:upper:]" "[:lower:]")
[ ! -d "$DESTDIR" ] && mkdir "$DESTDIR"
find "$MAILDIR" -type f | while read N
do
cat "$N" | tr "[:upper:]" "[:lower:]" | grep -q "$TEXT"
if [ $? == 0 ]; then
mv "$N" "$DESTDIR"
fi
done
I also made the script create the DESTDIR in case it doesn't exist.
Offline
As far as making the script disregard the lower/upper case; something like this should work...
Ummm. `grep -i` would be simpler
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
3. if and only if the file contains the specified string move the file to DESTDIR.
-Thats not whats happening.
If i just have 1 file with the name, "Hello" and execute the script i will end up with the Hello file in my new folder and 0 messages.
If i have two files, say: "Hello" and "ZZZZZZ" it will move both files to the new folder.
If i have 3 Files: ZZZZ, YYYY, XXXX the script wont do anything.
What im saying is that if their is a single occurence of the TEXT string it will move every file to DESTDIR.
**The Subject is what matters the most**
Similar to the procmail rule file:
:0
^Subject:.*Hello
helloFolder
I can tell your an expert with UNIX.
You can prolly tell that i am not.
Last edited by oxoxo (2008-11-19 05:30:16)
Offline
I don't Know what is happening. The script does not care about names. There is nothing in the script that in any way checks what the name of a file is. What do you mean by names?
Procmail does not deal with file names, it seems to be dealing with the subject of an email rather than a file name. Maybe this is the source of confusion? Or are the files in MAILDIR called the same as the Subjects of the emails they contain?
Offline
fwojciec wrote:As far as making the script disregard the lower/upper case; something like this should work...
Ummm. `grep -i` would be simpler
The smiley looks eerily like your avatar
You are right of course
#!/bin/sh
MAILDIR="/home/filip/Mail/Inbox"
TEXT="Hello"
DESTDIR="/home/filip/Desktop/test"
[ ! -d "$DESTDIR" ] && mkdir "$DESTDIR"
find "$MAILDIR" -type f | while read N
do
cat "$N" | grep -iq "$TEXT"
if [ $? == 0 ]; then
mv "$N" "$DESTDIR"
fi
done
Last edited by fwojciec (2008-11-19 06:45:12)
Offline
<sigh>
Thanks for your guys' help!
Offline
Perhaps change the script to something like this...?
#!/bin/sh
MAILDIR="/home/filip/Mail/Inbox"
TEXT="Hello"
DESTDIR="/home/filip/Desktop/test"
[ ! -d "$DESTDIR" ] && mkdir "$DESTDIR"
find "$MAILDIR" -type f | while read N
do
cat "$N" | grep -iqE "^Subject:.*${TEXT}.*"
if [ $? -eq 0 ]; then
mv "$N" "$DESTDIR"
fi
done
Problem found - we need to use '-eq' instead of '==' to compare integers
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
Still moving everything when one instance of "hello" occurs.
#!/bin/bash
sed 's/^From/==END==\n==From==/'"$1" |\
sed -n 'H; ${g;s/\n/+=+/g;p}' |\
sed 's/==END==+=+==From==/\nFrom/g' |\
grep -E "$2" |\
sed 's/+=+/\n/g'
#Move files to DESTDIR
What im trying to do with that code is to read my Mbox now.
And somehow implement the sed commands that do what your program isnt
Offline
Allright so, This is what me and another had figured out:
#!/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/Hello
And it works so nice!
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:
: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:
"|IFS=' '&&exec usr/bin/procmail||exit 75 #username"
Now the most important file .procmailrc that ties everything together is as follows:
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 what i've been helped with.
Im not executing anything with these three files. At least i dont think so. ..
Offline
Pages: 1