Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9238823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:50:59+00:00 2026-06-18T07:50:59+00:00

I am totally unfamiliar with bash scripting, however I came across the following script

  • 0

I am totally unfamiliar with bash scripting, however I came across the following script that php’s sendmail routes through so I can trace any scripts that may be comprised by spammers.

This works great however the $PWD variable is not showing the file name, its only showing the file’s working directory.

Bash script: /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

Test script: /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"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:51:01+00:00Added an answer on June 18, 2026 at 7:51 am

    well, ${PWD} is short for “print working directory” (pwd is the command for that), and therefore it will give you only the working directory. that’s by design.

    also, the working directory doesn’t necessarily have anything todo with the full path of the script (neither your sendmail2 script, nor the php-script that calls sendmail2).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm totally unfamiliar with Python but I there is a piece of code that
I don't do database work that often so this is totally unfamiliar territory for
I'm getting totally crazy with the following script. The following command works as expected
Totally new to Capistrano. I have a local git repository that I want to
Totally confused here. I have a PARENT UIViewController that needs to pass an NSMutableArray
Totally a PHP noob here so sorry for the possibly basic question - here
I would like to type the following url into my browser: localhost/mydomain/about.php And have
Seems totally backward to me that such an excellent IDE would hide line numbers
Am I totally missing what this is supposed to do? I expect that if
Totally simple situation, but I can't make it work. I am running into an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.