I've been trying to pipe an incoming email to a perl script so that I can monitor potential issues with invoices being emailed, and am not having much luck. Working on Red Hat Linux 2.6.32-696-6.3.el6.x86_64, cPanel 56.0 (build 51), and Exim 4.87
Using cPanel, I've forwarded emails received by test@someaddress.com to |/home/myuser/emailtest.pl
. The script I've cobbled together from different searches looks like this (script permissions set to 755):
#!/usr/bin/perl
# This is a test!
use strict;
use warnings;
use File::Touch;
use File::stat;
use Time::localtime;
my $file_list = ('/home/myuser/testfile');
touch $file_list;
my $timestamp = ctime(stat($file_list)->mtime);
#print $timestamp;
#print "\n";
I was originally getting a bounceback error, after some reading I saw it was probably because I was printing the timestamp. I don't really need to print the timestamp, I was just doing that when I was running the script myself to verify that I could 'touch' the file, and also read the date. After commenting out the print commands, no more bounceback. Script still works when run from shell, and I can verify the timestamp from 'ls', but still not luck when I send an email to my test account.
It doesn't seem like the script is successfully touching the file when an email arrives, though. I don't get a bounceback, but the 'testfile' never changes unless I manually run the script from the shell. I've tried moving the script into /home/myuser/public_html as well but same result.
I would like to ultimately be able to 'touch' the file when a email is received, then use a daily cron job to check the timestamp of the file. If 4 days go by without a change to the file, I want it to shoot me an email and let me know that there may be a problem. I'd like to throw a check in there to not bother touching the file if it's already the current date, but all of that hinges on being able to 'touch' the file first based on an incoming email and that's where I'm stuck.
Can anybody see what the issue is here? I'm not committed to solving this using Perl if PHP (or another solution) is better suited for this, or if there is something else I'm overlooking.