Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Run a script based on the subject line of the email

Shell Programming and Scripting


Tags
email, procmail, shell scipt

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-08-2009   -   Original Discussion by satekn
satekn's Unix or Linux Image
satekn satekn is offline
Registered User
 
Join Date: Apr 2009
Last Activity: 11 May 2009, 1:54 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Unix or Linux Question Run a script based on the subject line of the email

Hi,
I need help in running a script that would pull info from an email subject line and run a script (foo.sh). I'm pretty sure after a bit of googling that this is possible in several ways. but none was pretty clear on how to accomplish it. The part that I really need help with is getting the info from the email subject and pass it to the script as parameter. I am also considering perl as an option and would use perl if advised.

Basically i get emails with a standard subject line saying:

from: boss@email.com
Sub: DO this job=job1 copies=copy1

and i am planning to create a script dojob.sh job1 copy1.

i am typically looking for some way to accomplish this. i am pretty much new to unix (i am now in charge of some processes in HP-unx and AIX). I need to get these done in order to save my job. Typically whoever was in this position before were fired failing to accomplish this. I hope somebody will help me save my job here.

Any help would be greatly appreciated.

Thank you,
Sponsored Links
    #2  
Old Unix and Linux 04-09-2009   -   Original Discussion by satekn
nobody4's Unix or Linux Image
nobody4 nobody4 is offline
Registered User
 
Join Date: Nov 2005
Last Activity: 11 April 2009, 12:49 PM EDT
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
You probably need to spec this a bit better.
It's not clear whether you need help with writing the "dojob.sh" script,
or with taking the subject line and using the information in it to invoke
the command "dojob.sh job1 copy1"

You might be looking for this:

$ sed -n -e 's/^Sub:.*job=\(.*\) copies=\(.*\)$/dojob.sh \1 \2/p' emailfile
dojob.sh job1 copy1

...which you could pipe to a shell to get it executed.



Curious people might want to know whether you have some way of intercepting
the emails and processing them automatically as they come in,
or if you plan to do this manually with copy/paste and your email client (for example).
Sponsored Links
    #3  
Old Unix and Linux 04-10-2009   -   Original Discussion by satekn
satekn's Unix or Linux Image
satekn satekn is offline
Registered User
 
Join Date: Apr 2009
Last Activity: 11 May 2009, 1:54 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
i am trying to accomplish reding the subject line of the email and parsing the parameter to the script which i am creating to do the job.

The point is to run the script as soon as the email arrives.

Example:

Email: Sub: Dojob param1=ABC param2 = 3

i need a way to run the script like this. myscript.sh ABC 3.

Note: i already have the script which is run manually after reading the mail . I have to type the parameters and run it every single time. I now want a way or a program that can read this email subject(which has a fixed format) and run the script automatically.

I hope i am clear
    #4  
Old Unix and Linux 04-10-2009   -   Original Discussion by satekn
zedex's Unix or Linux Image
zedex zedex is offline
Registered User
 
Join Date: Feb 2007
Last Activity: 20 July 2017, 9:10 AM EDT
Location: Mumbai, India
Posts: 185
Thanks: 6
Thanked 5 Times in 5 Posts
in perl you have to use mail parser for this which will give you exact subject

i have worked on such kind of application which used to read mails then depending upon the mail contents it used to do the job. but for that there were some standards used you have to do the same.
Sponsored Links
    #5  
Old Unix and Linux 04-16-2009   -   Original Discussion by satekn
satekn's Unix or Linux Image
satekn satekn is offline
Registered User
 
Join Date: Apr 2009
Last Activity: 11 May 2009, 1:54 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by zedex View Post
in perl you have to use mail parser for this which will give you exact subject

i have worked on such kind of application which used to read mails then depending upon the mail contents it used to do the job. but for that there were some standards used you have to do the same.
i am a complete idiot when it comes to these standards or unix, but i can learn real quick as long it is a Programming language. So can you please make available your above mentioned stuff. it will be very useful.

Thanks,
Sponsored Links
    #6  
Old Unix and Linux 04-16-2009   -   Original Discussion by satekn
zedex's Unix or Linux Image
zedex zedex is offline
Registered User
 
Join Date: Feb 2007
Last Activity: 20 July 2017, 9:10 AM EDT
Location: Mumbai, India
Posts: 185
Thanks: 6
Thanked 5 Times in 5 Posts
sorry dude i dont have the source code .. as i left the firm you can search on CPAN about mail parser ( or HTML parser )

in brief application used to convert HTML mail in 2 parts
1 - header
2 - body

and then used simple HTML module to parse subject , cc , bcc and other details
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
inserting grep -c value into an email subject GrendelPrime Gentoo 3 08-01-2008 04:03 PM
Email with subject contains value of Variable deepsingh Shell Programming and Scripting 2 06-19-2008 05:20 PM
sort mail based on subject in unix. sriram.s Shell Programming and Scripting 2 02-02-2007 07:38 AM
creating email based on an output saswerks Shell Programming and Scripting 1 02-14-2005 06:57 PM
use email subject line as shell command mskarica UNIX for Advanced & Expert Users 4 02-01-2005 12:23 AM



All times are GMT -4. The time now is 09:46 AM.