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 automatically forward the subject line to the unix command prompt. Any ideas??

My other problem is that these emails will have attachments. I want these attachments to be saved to the home directory (or any other directory) automatically when the email is received.

Any help will be greatly appreciated.

Im in graduate school in Software Engineering. We use an email repository system built by the dean of our department that is used for students to submit their programming assignments to the instructor. The system is implemented using C shell scripts. The downfall of the system is that the student must be at school, logged in to their unix account in order to submit their program to the instructor.

I'm trying to find a way that will enable students to email their program to the instructor from home using their hotmail, yahoo, or any other email system so that they do not need to be at school to submit their programs. I'm trying to accomplish this by having a script run automatically when an email is received on the instructors unix email account. The script will check the first word of the subject line, if the first word is "XSsubmit" then I want to save all of the attachments to a directory (the files must be in the directory for the submit command to submit the files), then forward the entire subject line to a command prompt and run the command. Then this will submit the files to the instructors submission repository.

This is where my problem comes in. I need to get the attachments saved to the directory automatically, and then I need to get the subject field to a command prompt to invoke the submit script but have no idea how to.

I was going through some of the forum questions and saw that you are not supposed to post homework questions. This is not a homework assignment that I'm doing, its an entire project that I am working on that I'm trying to actually get into production.

Any help, pointing in the right direction like a book, website, anything would be great.

For the good or the bad of it, I've used systems similar to this before web browsers were widely used. In fact, one that comes to mind was Oracle's support site; albeit, commands were not issued to the O/S but were interpreted by some application running somewhere. You could submit trouble tickets, query status, etc. Another that comes to mind was an ftp service that would email you chunks of files that could be reassembled later on. This was useful when some networks were too young to offer more than email capabilities.

Your problem seems easy enough to solve. You're going to want to loop through all of your new messages issuing whatever commands necessary to save off the message body to the filesystem. Then, once the files are saved, launch your subject line command.

Here are some things that may help you get started.

Supposing that you wish to use mailx to process the message, you'll want to loop through the messages and filter on your key word:

For my quick test, I sent myself a message with "RunMe=ls" in the subject line. mailx shows this to be the last field of the output of mailx -H

$ mailx -H

N  4 Joe Smith     Mon Jan 31 16:44  111/2759  RunMe=ls

So I can run something like this and use the UNIX eval comand to process some of the text in the subject line (you wanted csh but I don't use csh; here's ksh):

#!/bin/ksh
mailx -H  | grep RunMe | while read LINE
do
    SUBJECT_CMD=$(print ${LINE} | awk -F= '{print $2}')

    # Parse more of ${LINE} and issue some command to save the message body to the filesystem
    ...
    # now run the subject text
    eval ${SUBJECT_CMD}
done

All this did was parse out the last field that mailx -H. The text following the "=" symbol was passed to the UNIX eval command. eval will execute the contents of the string ${SUBJECT_CMD}. The output happens to be that of a simple "ls" command.

Hope this helps you get closer toward your solution.

Thomas

Actually, my dean is a pretty good programmer, at least with shell scripts. He gave me a clue on what to do, so I'll post it for anyone to see.

In the home directory you can put a file named .forward in which you can forward your email. In the .forward file I can forward the emails to a script instead of to another email address. When the email is forwarded to the script, the subject and the body of the email is passed into the script as parameters......something like that......thats where I'm at right now, so I will do some more research on this.

Thanks for the reply tmarikle, I'll look into what you said also. It looks like that would help out also.

This is a somewhat easy problem to solve with procmail.

www.procmail.org

That is what I use for all these types of solutions. After you get familar with procmail, you can do many things you would never dream of using mail as an input to a filter :cool:

Neo