LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 04-19-2003, 03:11 PM   #1
Syncrm
Member
 
Registered: Aug 2001
Location: Lansing, Michigan
Distribution: slackware8+
Posts: 472

Rep: Reputation: 30
run script when email is received


hello all.

i just recently got a new cell phone (nokia 3650) and am already geeking the crap out of it. :-)

anyway... the camera is real cool and being able to send pictures to people is awesome. but what i want to do is be able to email them to a specific account and then have a perl script i wrote auto-generate thumbnails and pretty much photo album it and make available online.

pretty much the only thing standing in my way is actually executing the perl script when the email is received (through sendmail on a slack8 box). i'm wondering if anyone has any suggestions of how to execute a perl script whenever an email is received?

thanx!

(and i thoroughly recommend this phone)
 
Old 04-19-2003, 03:19 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
Look at using the /etc/aliases file - you can pipe the incoming message to a specific user into a program (or script)
 
Old 04-19-2003, 03:33 PM   #3
Syncrm
Member
 
Registered: Aug 2001
Location: Lansing, Michigan
Distribution: slackware8+
Posts: 472

Original Poster
Rep: Reputation: 30
interesting.... i hadn't thought of that. my aliases file is actually /etc/mail/aliases, and looks something like this:

# Basic system aliases -- these MUST be present.
MAILER-DAEMON: postmaster
postmaster: root

# General redirections for pseudo accounts.
bin: root
daemon: root
games: root
ingres: root
nobody: root
system: root
toor: root
uucp: root

# Well-known aliases.
manager: root
dumper: root
webmaster: root
abuse: root

# trap decode to catch security attacks
decode: root


which is the standard file. what would you suggest adding?
 
Old 04-19-2003, 03:39 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
I have never written a program to use this but I have used one. You need to add a line to your aliases file like:
Code:
auto.process: "|/path/to/myscript.pl"
This will forward all mail to "auto.process@yourdomain.com" to the program "/path/to/myscript.pl".

After you update the aliases fiel you need to run the program "newaliases".
 
Old 04-19-2003, 06:55 PM   #5
Syncrm
Member
 
Registered: Aug 2001
Location: Lansing, Michigan
Distribution: slackware8+
Posts: 472

Original Poster
Rep: Reputation: 30
hmmmm.... that doesn't appear to have worked. here's what i put in my alias file:

images: "|/usr/local/eportal/email.album.pl"

i restarted sendmail and also initiated the new alias.

however the script is still not being executed. hrmmmm.
 
Old 04-19-2003, 07:06 PM   #6
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
I have had a look at the sendmail config files on my redhat system - I'm not sure of the default setup on slack but my aliases file is /etc/aliases and is defined that way in the config file.

1) Backup your /etc/sendmail.cf file
cp /etc/sendmail.cf /etc/sendmail.cf.bak
2) Modify your /etc/mail/sendmail.mc file to allow aliases
3) Build it into sendmail.cf using:
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
4) Copy sendmail.cf to /etc
cp /etc/mail/sendmail.cf /etc/

Sorry I'm not sure about the paths in slack but that should get you started.
 
Old 04-19-2003, 09:28 PM   #7
Syncrm
Member
 
Registered: Aug 2001
Location: Lansing, Michigan
Distribution: slackware8+
Posts: 472

Original Poster
Rep: Reputation: 30
everything's working fine as far as sendmail's concerned. aliases is being used correctly in sendmail.cf and what have you. i've made changes to the config file many times before, so i'm reasonably sure everything is working how it's supposed to be. with the minor exception, of course, of this problem.

what would really help is if i could track down the point of failure. the mail seems to go through fine, but obviously the script isn't being executed.

where does sendmail usually keep logs?
 
Old 04-19-2003, 11:23 PM   #8
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 77
/var/logs/sendmail probably. It would most likely be specified in your config file.
 
Old 04-20-2003, 09:48 AM   #9
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
As far as I can remember it also creates a file called dead.letter (not sure of the case) that contains all messages that could not be processed.

I take it that your script is not being run at all - you could put a command like this near the top of the script:
system("echo `date` > /tmp/scriptcheck");

Then at the end
system("echo `date` >> /tmp/scriptcheck");

This should just print the start and end time that the script is run into a temporary file called "/tmp/scriptcheck".

I take it that the permissons on the file are OK? I'm not sure which user the script will be run as so you may want to give it 755 permissions.
 
Old 04-20-2003, 05:38 PM   #10
Syncrm
Member
 
Registered: Aug 2001
Location: Lansing, Michigan
Distribution: slackware8+
Posts: 472

Original Poster
Rep: Reputation: 30
ok, i got the result i'm looking for through .procmailrc in the ~/ directory of the user. however, i'm unable to access the data inside the cgi/perl script. here's the syntax of .procmailrc:

:0
| "/home/images/email.album.pl" $1

the script is executed upon receiving an email, however i'm unable to access the data which should be passed into the script. i've tried @ARGV and %ENV but neither contains the data.

any suggestions?
 
Old 04-20-2003, 05:57 PM   #11
Syncrm
Member
 
Registered: Aug 2001
Location: Lansing, Michigan
Distribution: slackware8+
Posts: 472

Original Poster
Rep: Reputation: 30
nm, i got it...:

while(<>) {
print $_;
}

that's exactly what i'm looking for. now i can grab the image data from the email, save it to the hdd and execute all the mysql processing. :-)

dunno why while(<>) didn't dawn on me sooner... must be cause it's april 20th. ;-)

Last edited by Syncrm; 04-20-2003 at 05:58 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script to run pl/sql script. colly Linux - General 1 09-09-2004 07:49 AM
Run email script from clamav Pete M Programming 0 07-25-2004 05:38 PM
How to count number of argument received by a script? philipina Linux - General 2 07-05-2004 03:35 AM
on Network Up Script run? On Battery power run script? v2-ncl Linux - General 0 12-08-2003 10:34 AM
can't run a script script from icon in konqueror scottsteibel Linux - Software 1 08-02-2003 08:59 PM


All times are GMT -5. The time now is 09:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration