1) How do you know for sure that the program is getting
executed?
2) What user is the script running as? Does it have the
correct permissions?
3) With that in mind, you should be checking the return
of open (always check the returns of system calls!):
open (MAIL, ">/home/brian/mail.txt")
or die "Can't open: $!";
print MAIL "\n";
while (<STDIN>) {print MAIL $_}
close MAIL
or die "Can't close: $!"
Is the file ever created, even? Is anything ever written
to it? | [reply] [d/l] |
I have to say it's probably number 2.
[root@archaia /root]# su nobody
[nobody@archaia /root]$ perl -e 'open (MAIL, ">./foo");print MAIL "scr
+atchymonkey.\n"
;'
[nobody@archaia /root]$ exit
[root@archaia /root]# ls
bin mod_perl_docs
[root@archaia /root]#
Note how there's no error at all, but the file isn't there.
Let's try it with -w :
[nobody@archaia /root]$ perl -we 'open (MAIL, ">./foo");print MAIL "sc
+ratchymonkey.\n
";'
print on closed filehandle main::MAIL at -e line 1.
Hmm, what's going on there?
[nobody@archaia /root]$ perl -we 'open (MAIL, ">./foo") || die "$!";pr
+int MAIL "scrat
chymonkey.\n";'
Permission denied at -e line 1.
What user does sendmail run as on your box?
Check the open() as above...
| [reply] [d/l] [select] |
don't forget to "close MAIL" | [reply] |
There are some things you could try. First, verify that
the file really can be written to:
open(">file") || die "couldn't open file: $!";
Alternatively, if the script just hangs at the end, you
could try unbuffered output:
$| = 1;
And of course, you should always close the file when you're
done with it, although this should be implicit.
Hope this helps... | [reply] |
As written, your mail.txt file is only ever going
to have the most recent message in it if you open
the file handle for writing:
open(MAIL, ">/home/brian/mail.txt");
if you want a spool file (list of all messages), you'd need
to open the file handle for appending:
open(MAIL, ">>/home/brian/mail.txt");
While you're at it, you should probably lock the file while you
are writing to it, so the next piece of inbound mail
doesn't try to screw with your mail.txt file while
you are already writing to it.
(this code is ripped from OraPP2ndEd, p 166-7)
flock MAIL, 2;
seek MAIL, 0, 2; # skip to the end for spooling
while (<STDIN>) {print MAIL $_;}
flock MAIL, 8;
close MAIL || die($!);
Note that flock can't be tested with die, since it waits
until the file is "freed up" for locking. If your system
doesn't implement flock, you'll get a fatal runtime error,
AFAIK | [reply] |
Your're right, i'm now pretty sure it isn't running. My sendmail is really rusty. Anybody out there who can tell me how to fix the problem of my .forward program not running as me? =Brian | [reply] |
| [reply] |