nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Call mutt macro from shell script

This is a discussion on Call mutt macro from shell script within the Mail Servers forums, part of the Mastering Servers category; I have a macro code that selects a particular message and saves the attachment file to a directory, and exits. ...


Go Back   nixCraft Linux Forum > Mastering Servers > Mail Servers

Linux answers from nixCraft.


Mail Servers Discussion on Postfix/Sendmail Mail servers and related program such as IMAP/POP3, Anti-Spam technologies.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 17-06-2009, 02:08 AM
Junior Member
User
 
Join Date: Jun 2009
OS: Debian
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Rep Power: 0
gheorghiua is on a distinguished road
Cool Call mutt macro from shell script

I have a macro code that selects a particular message and saves the attachment file to a directory, and exits.
I created a bash script which calls mutt as follows:

Code:
mutt -e 'push "i"''
if [ -s cdrs.csv ]; then
mv cdrs.csv vitcd.csv
chmod 755 vitcd.csv
When executed from the command line it saves the attachment of the selected mail as cdrs.csv with no problems
However, when this script is executed from cron or command line it gives the following errors:
Code:
No recipients were specified.
Vitelity raw file could not be generated!"
Tried everything to no avail. Macro code in .muttrc is as follows:
Code:
 macro index i "<l ~d<1d,l ~s CDR^M<enter>v<next-entry><next-entry>s<enter><exit><exit><exit>"
Any tips would be greatly appreciated as this job cannot be scheduled to run by itself, and it needs manual intervention for this step.
Thanks so much

Last edited by nixcraft; 17-06-2009 at 04:46 AM. Reason: added
Reply With Quote
  #2 (permalink)  
Old 17-06-2009, 03:15 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 246 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Are you running this from your own crontab or from root users crontab?
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 17-06-2009, 03:44 AM
Junior Member
User
 
Join Date: Jun 2009
OS: Debian
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Rep Power: 0
gheorghiua is on a distinguished road
Default

I am running my own crontab as there are no other jobs on that machine (CentOS 5.2)
Reply With Quote
  #4 (permalink)  
Old 17-06-2009, 05:08 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 246 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Few quick things try using full path to mutt (/usr/bin/mutt)

Export the variables (cron will not export all these variables):

  • EMAIL The user’s e-mail address.
  • MAIL Full path of the user’s spool mailbox.
  • MAILDIR Full path of the user’s spool mailbox. Commonly used when the spool mailbox is a maildir folder.
For e.g.
Code:
export MAIL=/var/spool/mail/vivek
Try the -f mailbox option to mutt which specify which mailbox to load:

PHP Code:
 mutt -/var/spool/mail/vivek -'push "i"'' 
When you run crontab -u user -e make sure crontab has default shell and MAILTO defined:
Code:
 # use /bin/bash to run commands
SHELL=/bin/bash
# mail any output to vivek
MAILTO=vivek
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #5 (permalink)  
Old 17-06-2009, 10:27 AM
Junior Member
User
 
Join Date: Jun 2009
OS: Debian
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Rep Power: 0
gheorghiua is on a distinguished road
Default

I tried suggestions 2. Suggestion 3 was already applied on crontab. As far as suggestion 1 it seems cron already finds the var/spool/mail/alice, and tested again with the same results. Forgot to mention, I have fetchmail that is transferring the e-mail from my gmail account. The settings being in the fetchmailrc. What I have noticed though, is that after I run the first time around, with failure, and if I open the terminal I am alerted that new mail is waiting in /var/spool/mail/alice. After that if I run the script again with fetchmail and mutt it successfully saves the desired attachment and completes the rest of the steps. My question would be now how can I supress this message by a command which will place the e-mail to the mbox which is on my home directory.
Thank you again so much for all the suggestions.
Reply With Quote
  #6 (permalink)  
Old 17-06-2009, 07:20 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 246 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

So fetchmail download email from gmail pop3 server and mutt moves attachments to folders? Try mda command in $HOME/.fetchmailrc
Code:
poll pop3.gmail.server
protocol pop3 
user 'you@gmail.com' 
password 'your-gmail-password' 
mda '/home/you/path/to/mutt.bash.script.sh'
Try above, if that failed the only real and valid solution is to use procmail to move the attachments. I've done fetchmail and procmail combo to move attachments.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
The Following User Says Thank You to nixcraft For This Useful Post:
gheorghiua (17-06-2009)
  #7 (permalink)  
Old 17-06-2009, 11:24 PM
Junior Member
User
 
Join Date: Jun 2009
OS: Debian
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Rep Power: 0
gheorghiua is on a distinguished road
Default

I tried adding the mda on the .fetchmailrc and re-ran the script with the following result:
Code:
cat cdrtest.log
we move to cdrf and run fetchmail
2 messages for alice@ringplus.net at pop.gmail.com (70785 octets).
reading message alice@ringplus.net@pop.gmail.com:1 of 2 (8256 octets)........we move to cdrf and run fetchmail
fetchmail: another foreground fetchmail is running at 25170.
we now run the mutty
Wed Jun 17 13:45:06 EDT 2009
No recipients were specified.
No recipients were specified.
Vitelity raw file could not be generated!
flushed
reading message alice@ringplus.net@pop.gmail.com:2 of 2 (62529 octets).
I tried b4 with procmail but wasn't sure how it works. Will continue to approace this idea. Any tips will be appreciated.

Last edited by nixcraft; 18-06-2009 at 10:18 PM. Reason: ad a comment which I forgot
Reply With Quote
  #8 (permalink)  
Old 18-06-2009, 10:30 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 246 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Yes, you can use something as follows which redirect common virus attachments including zipped versions using procmail.
Code:
    :0 B
    * name=.*(document|readme|doc|text|file|data|test|message|body)\.(vbs\"|wsf\"|vbe\"|wsh\"|hta\"|scr\"|pif\"|exe\"|shs\"|bat\"|bas\"|cmd\"|zip\")
    {
        :0
        /dev/null
    }
I've attached a sample config file. It has lots of examples. It can help you to write task for your own purpose.
Attached Files
File Type: txt procmail-tips-tricks-recipes.txt (16.0 KB, 2 views)
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
The Following User Says Thank You to nixcraft For This Useful Post:
gheorghiua (19-06-2009)
  #9 (permalink)  
Old 20-06-2009, 12:41 AM
Junior Member
User
 
Join Date: Jun 2009
OS: Debian
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Rep Power: 0
gheorghiua is on a distinguished road
Default

I put together a .procmailrc file with a setting I thought maybe my case. I attached herein the 3 config files (.muttrc, .fetchamilrc, .procmailrc hope they were taken in my upload). I found there is a new player now: 'sendmail' program which is set-up in the .procmail, and I am asking how I would run now the fetchmail and mutt to accomplish the following:
1. Get the e-mail from my gmail pop server
2. Move the e-mail from my provider (specified in .procmailrc)
3. Run mutt in command line and select that particular mailbox cdrs (which is in ~/Mail/cdrs) and operate on the newest message (the macro I have will take care of the message once I tap in that mailbox acording to a command line option for mutt or a .muttrc setting).
Sorry for being a pain.
Thanks so much again for any tips on how to 'put order in the chaos'
Reply With Quote
  #10 (permalink)  
Old 20-06-2009, 01:12 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 246 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Rename and upload them as a text file.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
Reply

Tags
cron , cronjobs , crontab , linux , mutt


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Call for Papers - NCOSS 2009, C-DAC Mumbai ncoss2009 The Hangout 3 14-05-2009 04:30 PM
Mutt in a script with attachments fkempers Shell scripting 1 28-12-2008 11:49 AM
Binary Conversion Of Shell Script (shell script compiler) chandanperl Shell scripting 3 29-07-2008 10:22 AM
Call Logging and Asset Mgmnt SW ricc Linux software 1 29-06-2007 01:45 AM
call function in bash mala_un Shell scripting 9 18-08-2006 01:36 AM


All times are GMT +5.5. The time now is 08:55 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38