Sendmail works from script, but not when called from Apache
Hi,
I am building a web interface to run a series of shell scripts that reside on the web server. The bash script are written such that they can be used independently for the task they are meant for, or the same scripts can be run from this web UI. The scripts are mostly for doing software builds, testing, and uploading to another server. The webpage issues a call out to a tiny PHP script that calls the bash shell script. In one of the scripts I am trying to add the ability to send an e-mail with sendmail when a software build fails. It looks something like this:
When I run this script from the command line it works perfectly fine! No errors, and I get the e-mail, all is good in the world.
Now when I invoke the SAME script file via the web UI it produces the following error:
"SendMail: fatal: Recipient addresses must be specified on the command line or via the -t option"
As you can see I AM specifying the address on the command line, and I have also tried it with -t and putting the address in the file. But neither way works when the bash script is called from apache by way of the PHP script. I have spent hours trying to figure this out with no luck. Note, this is all running on Mac OS X. Can anyone provide any assistance, or pointers to relevant informaion?
Note, when I run the script manually from a Terminal window (when it works) I am logged in as an administrative user (not root), call it user_a. Apache is set in its config file to also run as the same administrative (non-root) user, user_a. (And yes I confirmed it is indeed running as that user.) The sendmail command is just a line in the bash script so it should be running as the same user that invokes the script - that would be the user apache is running as - or user_a.
Also, when googling this error it turns up a lot of pages about PHP & Drupal and setting the PHP.ini file to use the -t flag when calling sendmail. But that has nothing to do with my problem. My call to sendmail is not occurring from inside PHP, to be clear, it is inside a bash script that gets called by PHP.
I hate to admit it, but this was actually something really simple.
I had the portion of the script that sent the e-mail in a separate file, that was (supposed to be) sourced at the top of the main script. When I was running the main script interactively from the command line (when everything worked) it worked because I had already manually sourced that other file earlier in the Terminal session. And when apache was calling that other file it didn't work because that file hadn't been sourced yet. The reason it showed up as a sendmail error message was because in that other file I had named the routine that sent the e-mail "SendMail" as opposed to "sendmail" but when that other file wasn't sourced it was calling the normal sendmail program with no parameters -- thus the error.
Multiple mistakes here: 1) naming the separate routine "SendMail" rather than something more unique, 2) not sourcing the other file at the top of the main file.
Need ideas on how to achieve the below.
We have a script say "profile.sh" which internally calls another existing script called "name.sh" which prompts for the
name and age of a person upon execution. When i run profile.sh how can i populate a pre-defined value from another file and pass that... (1 Reply)
I want to make a config file which contain all the paths.
i want to read the config file line by line and pass as an argument on my below function.
Replace all the path with reading config path line by line and pass in respective functions.
how can i achieve that?
Kindly guide.
... (6 Replies)
Hi, I've got a Bash backup script I'm trying to run on a directory via a cron job nightly. If I ssh in and run the script manually it works flawlessly. If I set up the cron to run evertything is totally messed up I don't even know where to begin.
Basically the path structure is
... (6 Replies)
Hi,
I am trying to capture logs of the script in the file as well as on the screen. I have used exec and tee command for this. While using exec command I am getting the correct output in the file but, script output is not getting displayed on the screen as it get executed.
Below is my sample... (14 Replies)
Hi all,
Warm regards!
I am in a difficult situation here. I have been trying to create a shell script which calls another shell script inside. Here is a simplified version of the same.
Calling Script.
#!/bin/ksh
# want to run as a different process... (6 Replies)
I am using blow script :--
#!/bin/bash
FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not
if
then
# echo "process found"
exit 0;
else
echo "process not found"
exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Having issues with an expect script. I've been scripting bash, python, etc... for a couple years now, but just started to try and use Expect. Trying to create a script that takes in some arguments, and then for now, just runs a pwd command(for testing, final will be command I pass).
Here is... (0 Replies)
Hi all,
I have two ksh scripts
#sample1.sh
#!/bin/ksh
. ./sample2.sh
echo $fileExist
#sample2.sh
#!/bin/ksh
func()
{
i=1
return $a
}
func
echo $?
Here how should I return the value of sample2.sh back to sample1.sh?
Thanks in advance. (2 Replies)
How do i get the value of the variable from the called script(script2) to the calling script(script1) in ksh ?
I've given portion of the script here to explain the problem.
Portion of Script 1
=============
-----
-----
tmp=`a.ksh p1 p2 p3`
if then
# error processing
fi
-----... (10 Replies)
Excuse me for this question really for dummies!
I would like to know how sendmail works, obviously even in few words.
If it uses a mail server or relay to send mail, if there is some check that sendmail makes to the from address and so on...
Thank you very much. (3 Replies)