Run a script based on the subject line of the email

Tags
email, procmail, shell scipt, shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 04-08-2009
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,
# 2  
Old 04-09-2009
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).
# 3  
Old 04-10-2009
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 04-10-2009
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.
# 5  
Old 04-16-2009
Quote:
Originally Posted by zedex
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,
# 6  
Old 04-16-2009
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
Login to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
To run the script based on dates rohit_shinez Shell Programming and Scripting 9 12-08-2017 03:08 AM
Script that will send an email if the cron job did not run. kenshinhimura Shell Programming and Scripting 4 03-23-2017 03:57 PM
Sending sql output to email body with conditional subject line itzkashi Shell Programming and Scripting 10 03-15-2017 04:20 AM
Run a script when I receive an email emi65 Shell Programming and Scripting 3 02-14-2012 02:39 PM
help with email to be triggered based on fatal error detection from batch run log file neded zico1986 Shell Programming and Scripting 1 09-06-2011 03:51 PM
To run a script based on the value in text file nani1984 Shell Programming and Scripting 7 12-29-2010 09:37 PM
Subject line of an email smarty86 Shell Programming and Scripting 4 12-20-2010 02:26 AM
Run PHP script when new email received iKris Linux 16 10-14-2010 04:50 PM
help with script to send email and if subject line match is found axdelg Shell Programming and Scripting 2 07-07-2010 05:43 PM
run a perl.script upon receiving an email in Sendmail manustone UNIX for Dummies Questions & Answers 0 07-16-2009 04:21 AM
Shell script to email based on flat file output apoorva Shell Programming and Scripting 1 05-12-2009 11:53 AM
trigger a script based on the run status of another scipt Athena Shell Programming and Scripting 1 10-02-2008 03:11 PM
Running script that sends an html formatted email fails when its run as cronjob Nightowl Shell Programming and Scripting 15 09-17-2008 08:27 AM
run a script from incoming email jojo77 UNIX for Dummies Questions & Answers 7 02-22-2008 01:48 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 08:27 PM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?