Run a script based on the subject line of the email


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run a script based on the subject line of the email
# 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 or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Variable not displaying in subject line of mailx email

Hi Newbie here with first post. I've got a shell script (ksh) whereby I run a SQL*Plus script and output the results to a file. I then check the output file in an if statement that looks like this: if ]; then export GAPNUM=`awk '{print $4}' $OUTFILE` if ] then mailx -s... (10 Replies)
Discussion started by: ltzwoman
10 Replies

2. Shell Programming and Scripting

Script that will send an email if the cron job did not run.

Team, Would like to know what is the best script that will send you an email if cronjob did not run. Thanks (4 Replies)
Discussion started by: kenshinhimura
4 Replies

3. Shell Programming and Scripting

Sending sql output to email body with conditional subject line

hi , i have written below piece of code to meet the requirement but i am stuck in the logic here. the requirement are: 1) to send the sql out put to email body with proper formatting. 2) if count_matching = Yes then mail should triggered with the subject line ... (10 Replies)
Discussion started by: itzkashi
10 Replies

4. Shell Programming and Scripting

Run a script when I receive an email

Hi expert I wish to start a shell script when I receive an email. I modified the aliases file and I add this string as400nag: "|/home/nag-script/startstop/AS400-Boot.sh The solution works . When the as400nag user receive an email the /home/nag-script/startstop/AS400-Boot.sh starts .but... (3 Replies)
Discussion started by: emi65
3 Replies

5. Shell Programming and Scripting

help with email to be triggered based on fatal error detection from batch run log file neded

Hi, I require need help in two aspects actually: 1) Fatal error that gets generated as %F% from a log file say ABClog.dat to trigger a mail. At present I manually grep the log file as <grep %F% ABClog.dat| cut-d "%" -f1>. The idea is to use this same logic to grep the log file which is... (1 Reply)
Discussion started by: zico1986
1 Replies

6. Shell Programming and Scripting

Subject line of an email

Hi all, I am trying to automate a process in which at the end of the process the script should send an email to the user saying this process is completed. I have done everything but the problem now is the subject line of the email... the subject line looks like this.. where abc xyz is a... (4 Replies)
Discussion started by: smarty86
4 Replies

7. Linux

Run PHP script when new email received

I have been looking around for a solution to this, i have been developing for a wile though am very new to CGI, PHP and a lot of the web based tech. I have a web site hosted with a cPanel web host. I am looking to have a script(prefer PHP) to run everytime i get a new email to help@xxx.com.... (16 Replies)
Discussion started by: iKris
16 Replies

8. Shell Programming and Scripting

help with script to send email and if subject line match is found

Help with script that will check log, then find a match is found, add that as the subject line. 1. The script will always run as a deamon.. and scan the event.log file 2. when a new 101 line is added to the event.log file, have the script check position 5,6 and 7 which is the job name, which... (2 Replies)
Discussion started by: axdelg
2 Replies

9. UNIX for Dummies Questions & Answers

run a script from incoming email

hi I have a bit of a problem i need help with. I have a script that runs no problems when i run it manually. as soon as i stick in tester: /app/scripts/run.pl into /etc/aliases & try to run it by sending a mail it doesnt work. the output files are owned by daemon, which i dont like & think... (7 Replies)
Discussion started by: jojo77
7 Replies

10. UNIX for Advanced & Expert Users

use email subject line as shell command

If anyone can give me some ideas on this it would be great. What I'm trying to do is to have emails be sent to my unix account. Once they are emailed to the unix account, I want to use the text in the subject field to invoke a shell script, so basically I need to find a way that I can... (4 Replies)
Discussion started by: mskarica
4 Replies
Login or Register to Ask a Question