Home Man
Search
Today's Posts
Register

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

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

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sending sql output to email body with conditional subject line itzkashi Shell Programming and Scripting 10 03-15-2017 03:20 AM
Getting email output in single line with out space in email mirwasim Shell Programming and Scripting 6 08-03-2016 07:52 AM
HELP: Shell Script to read a Log file line by line and extract Info based on KEYWORDS matching biztank Shell Programming and Scripting 8 07-24-2012 11:44 PM
How to read specific line of text from a Script and send email notification atechcorp Shell Programming and Scripting 2 02-11-2011 03:41 PM
Subject line of an email smarty86 Shell Programming and Scripting 4 12-20-2010 01:26 AM
Improve script made to calculate value based on present and previous line s052866 Shell Programming and Scripting 5 11-22-2010 07:08 PM
help with script to send email and if subject line match is found axdelg Shell Programming and Scripting 2 07-07-2010 04:43 PM
Awk script to create new file based on previous line Muga801 Shell Programming and Scripting 5 05-13-2010 08:13 AM
Shell script to email based on flat file output apoorva Shell Programming and Scripting 1 05-12-2009 10:53 AM
use email subject line as shell command mskarica UNIX for Advanced & Expert Users 4 01-31-2005 11:23 PM


All times are GMT -4. The time now is 04:57 AM.

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