我完全不熟悉 bash 脚本,但是我遇到了 php 的 sendmail 路由通过的以下脚本,因此我可以跟踪任何可能由垃圾邮件发送者组成的脚本。
这很好用,但是 $PWD 变量不显示文件名,它只显示文件的工作目录。
Bash 脚本:/usr/local/bin/sendmail2
#!/bin/sh
# Logging sendmail wrapper
SENDMAIL="/usr/sbin/sendmail -t -i"
LOGFILE="/home/mail.log"
DT=`date "+%Y-%m-%d %H:%M:%S"`
DTFN=`date "+%Y%m%d-%H%M%S"`
#TMPFP=`tempfile --prefix=lsm_`
TMPFP=`mktemp`
cat | tee "$TMPFP" | $SENDMAIL $*
RETVAL=$?
TO=`grep "To:" <"$TMPFP"`
rm -f "$TMPFP"
echo "$DT: $PWD sent $TO" >> $LOGFILE
exit $RETVAL
测试脚本:/home/mysite/test.php:
<?php
$to = "my@email.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "my@email.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
php.ini:
sendmail_path = "/usr/local/bin/sendmail2"