READING mail from /var/mail/user


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting READING mail from /var/mail/user
# 8  
Old 05-21-2006
Yup..it helps..Smilie...though I'm not sure how it works.
So

headers="(^From )|(^Message-IDSmilie|(^DateSmilie|(^FromSmilie|(^ToSmilie|(^SubjectSmilie"
headers can start with (From,Message-ID,Date...)

/^From/
and then if sentence start with "From" it does the for cyclus

printf("\n\n=== THIS is MAIL MESSAGE #%d ===\n\n", ++msg)
for(i=1; i<=NF; i++) {
if ( $i ~ headers) print $i
}

if the sentence is header then pprint? what does ( ( $i ~ headers)) this mean????

Also I would like to be able to write message text. The best would be if I could choose with Message number as you NAMED with evert message with last code.

THX a lot.
Peto
# 9  
Old 05-21-2006
ok, I've updated the code with comments - should be clearER now. If it's not - do 'man nawk'.
Quote:
Originally Posted by petoSVK
Yup..it helps..Smilie...though I'm not sure how it works.
So

headers="(^From )|(^Message-IDSmilie|(^DateSmilie|(^FromSmilie|(^ToSmilie|(^SubjectSmilie"
headers can start with (From,Message-ID,Date...)

/^From/
and then if sentence start with "From" it does the for cyclus

printf("\n\n=== THIS is MAIL MESSAGE #%d ===\n\n", ++msg)
for(i=1; i<=NF; i++) {
if ( $i ~ headers) print $i
}

if the sentence is header then pprint? what does ( ( $i ~ headers)) this mean????

Also I would like to be able to write message text. The best would be if I could choose with Message number as you NAMED with evert message with last code.
I don't understand what you're asking, but if you understand the code and/or give a sample desired output I believe you can format the output any way you want.

Good luck
# 10  
Old 05-21-2006
I got it, but wasnt sure. Now I understand it thx.

Is it possible to read from STDIN in NAWK? I cannot find it on internet. I would like to write max. 3 Mail Headers and then wait for user to press ENTER and then show next 3 headers and so on.

Well, I'm sorry if I didn't make my question clear. I don't really have any ideas how to write text written by sender in the /var/mail/user. I mean not just Header of the mail, but also mail and omit Msg Info for Server between Header and Message.
# 11  
Old 05-21-2006
Quote:
Originally Posted by petoSVK
I got it, but wasnt sure. Now I understand it thx.

Is it possible to read from STDIN in NAWK? I cannot find it on internet. I would like to write max. 3 Mail Headers and then wait for user to press ENTER and then show next 3 headers and so on.
Code:
BEGIN {
  # make 'records' to be separated by blank/empty lines
  RS=FS=""

  # create a pattern where something starts either one of listed strings
  headers="(^From )|(^Message-ID:)|(^Date:)|(^From:)|(^To:)|(^Subject:)"
}

# If a record starts with 'From ' ...
/^From / {

   if ( !(++msg % 4) ) {
      printf "Please press ENTER: "
      getline myInput < "-"
   }

   # print the record number
   printf("\n\n=== THIS is MAIL MESSAGE #%d ===\n\n", msg)

   # iterate through the fields of a given 'record' - every field is a LINE, 
   # because records are 'blank line' separated sequesnce of lines
   for(i=1; i<=NF; i++) {

     # if a record field (a line) matches a pattern 'headers' - print that field
     if ( $i ~ headers) print $i
   }
}

# print any OTHER 'record' - this is a shorthand for 'print $0'
1

Quote:
Originally Posted by petoSVK
Well, I'm sorry if I didn't make my question clear. I don't really have any ideas how to write text written by sender in the /var/mail/user. I mean not just Header of the mail, but also mail and omit Msg Info for Server between Header and Message.
I don't understand what you're saying.......

Last edited by vgersh99; 05-21-2006 at 07:24 AM..
# 12  
Old 05-21-2006
Ok.I'll try to start expressing myself a bit better Smilie.

Firstly, I considered last character '1' in peto.awk to be a typo so I didn't include it. But now as you've comment it, I see I was wrong. So I was asking exactly what you already did - sorry.

However, I'd like to ask one more question. Now, user can view 4 e-mails at once and then he is asked to press ENTER. However you have to press: CTRL+D and ENTER, ENTER(once more)
so it continues with printing out next mails. Is it possible to avoid this?

You helped me a lot and it's much clearer to me now.

Peto
# 13  
Old 05-21-2006
hmm....... it seems not ALL the awk's support this paradigm - Solaris's 'nawk' seems to be one of them.

Try this:
Code:
BEGIN {
  # make 'records' to be separated by blank/empty lines
  RS=FS=""

  # create a pattern where something starts either one of listed strings
  headers="(^From )|(^Message-ID:)|(^Date:)|(^From:)|(^To:)|(^Subject:)"
}

# If a record starts with 'From ' ...
/^From / {

   if ( !(++msg % 4) ) {
      printf "Please press ENTER: "
      cmd="read a"; cmd | getline foo
      close(cmd)
   }

   # print the record number
   printf("\n\n=== THIS is MAIL MESSAGE #%d ===\n\n", msg)

   # iterate through the fields of a given 'record' - every field is a LINE, 
   # because records are 'blank line' separated sequesnce of lines
   for(i=1; i<=NF; i++) {

     # if a record field (a line) matches a pattern 'headers' - print that field
     if ( $i ~ headers) print $i
   }
}

# print any OTHER 'record' - this is a shorthand for 'print $0'
1

# 14  
Old 05-21-2006
Works flawlessly now Smilie)).

Its nice to have such a good forum Smilie.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Client was not authenticated to send anonymous mail during MAIL FROM (in reply to MAIL FROM comm

I am having trouble getting mail to work on a red hat server. At first I was getting this message. Diagnostic-Code: X-Postfix; delivery temporarily suspended: connect to :25: Connection refused Then added the port to my firewall. Then I temporarily turned off selinux. I then copied this file... (1 Reply)
Discussion started by: cokedude
1 Replies

2. AIX

/var/spool/mail/ issues

Hi My box is running with AIX 6100-06 and Im the root user of this box My /var gets filled up often to 100% When I investigate I find that it is the below file which increases rapidly /var/spool/mail/pdgadmin I dont know why this file is growing up. Can any one assist me on this.... (2 Replies)
Discussion started by: samsungsamsung
2 Replies

3. UNIX for Advanced & Expert Users

need to configure mail setting to send mail to outlook mail server

i have sun machines having solaris 9 & 10 OS . Now i need to send mail from the machines to my outlook account . I have the ip adress of OUTLOOK mail server. Now what are the setting i need to do in solaris machines so that i can use mailx or sendmail. actually i am trying to automate the high... (2 Replies)
Discussion started by: amitranjansahu
2 Replies

4. Shell Programming and Scripting

importance of /var/mail

Hi When an entry will be made to the file /var/mail/<user-id> . I have 100 scripts under a specific user id(dgircc) in cron .SO inrder to check the whether the script has sucessfully run or not and if not to generate an email if i mention the code like #!/bin/ksh -p 2 fsize=`ls -lrt... (0 Replies)
Discussion started by: mskalyani
0 Replies

5. UNIX for Dummies Questions & Answers

Parse /var/mail

Hi all... We have a box that receives a lot of incoming emails. I have a .procmailrc file that in turn invokes a python script, which process each of these incoming email. All is nice and good. However, before the .procmailrc and python script were in place, we still were receiving emails and... (0 Replies)
Discussion started by: khader69
0 Replies

6. UNIX for Advanced & Expert Users

Mail going to /var/spool/mqueue instead of being sent

Hello, I have a bunch of cron jobs in the crontab. For some reason mail from the cron jobs started going to /var/spool/mqueue instead of being sent. Does anyone know why mail from cron jobs would go to the queue instead of being sent? (9 Replies)
Discussion started by: xadamz23
9 Replies

7. UNIX for Dummies Questions & Answers

/var/spool/mail

Hi, How can i get my mail on either /var/spool/mail or /var/mail? I use mail and sendmail command to send mail. But everytime I send mail it comes to my outlook inbox and when I check with mail command I get the message "No mail for siba". (Note siba is my user Id.) (2 Replies)
Discussion started by: siba.s.nayak
2 Replies

8. UNIX for Dummies Questions & Answers

How do I read mail in /var/spool/mail?

How can I read mail sent to /var/spool/mail? I do not have pine installed so forget about that...is there some generic utility I can use? (3 Replies)
Discussion started by: mojoman
3 Replies

9. Solaris

how to forward mail in /var/mail/username to external mail

Dear All, Now I use solaris 10 and I try to forward mail from /var/mail/username to their external mail so what should I do? thank u in advance (2 Replies)
Discussion started by: unitipon
2 Replies

10. UNIX for Dummies Questions & Answers

Can I zero var/spool/mail/mail

The mail file in the directory var/spool/mail is very large. Can I zero this (>) without losing any unopened mails there may be? There are about 10 mail accounts. Using RedHat Linux. Thanks in advance. (0 Replies)
Discussion started by: dennisheazle
0 Replies
Login or Register to Ask a Question