Sponsored Content
Top Forums Shell Programming and Scripting Sendmail works from script, but not when called from Apache Post 302520017 by MacQAGuy on Thursday 5th of May 2011 03:33:43 PM
Old 05-05-2011
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:

---------------------------------------------------------------------------------------
Code:
DistributionList="me@mydomain.com";
MessageFile="/tmp/build_failure_email.txt";

if [ -e $MessageFile ];
then
    rm $MessageFile
fi
 
#echo "To: $DistributionList" >> $MessageFile;
 
Subject="My Subject...";
echo "Subject: ${Subject}" >> $MessageFile;
 
FromName="My Name";
FromAddress="me@mydomain.com";
echo "From: $FromName <${FromAddress}>" >> $MessageFile;
 
 echo "Message Body line 1..." >> $MessageFile;
echo "Message Body line 2." >> $MessageFile;
 
/usr/sbin/sendmail "$DistributionList" < $MessageFile
#/usr/sbin/sendmail -t "$DistributionList" < $MessageFile

---------------------------------------------------------------------------------------

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.

Any help would be greatly appreciated.

THANKS!

MacQAGuy

Last edited by pludi; 05-05-2011 at 05:58 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how sendmail works

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)
Discussion started by: alzep
3 Replies

2. Shell Programming and Scripting

passing a variables value from the called script to calling script using ksh

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)
Discussion started by: rajarkumar
10 Replies

3. Shell Programming and Scripting

How to return the value from the called shell script to the calling sh script

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)
Discussion started by: gp_singh
2 Replies

4. Shell Programming and Scripting

Expect script called in loop from Bash Script

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)
Discussion started by: cbo0485
0 Replies

5. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

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)
Discussion started by: ketanraut
1 Replies

6. Shell Programming and Scripting

Passing variable from called script to the caller script

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)
Discussion started by: LoneRanger
6 Replies

7. Shell Programming and Scripting

Need output of script on screen and file with correct return status of the called script.

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)
Discussion started by: Prathmesh
14 Replies

8. Shell Programming and Scripting

Calling bash script works when called manually but not via Cron?

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)
Discussion started by: wyclef
6 Replies

9. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

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)
Discussion started by: sadique.manzar
6 Replies

10. UNIX for Beginners Questions & Answers

How to pass values to a script called from within another script in shell?

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)
Discussion started by: sankasu
1 Replies
ATF-SH(1)						    BSD General Commands Manual 						 ATF-SH(1)

NAME
atf-sh [-s shell] -- interpreter for shell-based test programs SYNOPSIS
atf-sh script DESCRIPTION
atf-sh is an interpreter that runs the test program given in script after loading the atf-sh(3) library. atf-sh is not a real interpreter though: it is just a wrapper around the system-wide shell defined by ATF_SHELL. atf-sh executes the inter- preter, loads the atf-sh(3) library and then runs the script. You must consider atf-sh to be a POSIX shell by default and thus should not use any non-standard extensions. The following options are available: -s shell Specifies the shell to use instead of the value provided by ATF_SHELL. ENVIRONMENT
ATF_LIBEXECDIR Overrides the builtin directory where atf-sh is located. Should not be overridden other than for testing purposes. ATF_PKGDATADIR Overrides the builtin directory where libatf-sh.subr is located. Should not be overridden other than for testing purposes. ATF_SHELL Path to the system shell to be used in the generated scripts. Scripts must not rely on this variable being set to select a specific interpreter. EXAMPLES
Scripts using atf-sh(3) should start with: #! /usr/bin/env atf-sh Alternatively, if you want to explicitly choose a shell interpreter, you cannot rely on env(1) to find atf-sh. Instead, you have to hardcode the path to atf-sh in the script and then use the -s option afterwards as a single parameter: #! /path/to/bin/atf-sh -s/bin/bash ENVIRONMENT
ATF_SHELL Path to the system shell to be used in the generated scripts. SEE ALSO
atf-sh(3) BSD
September 27, 2014 BSD
All times are GMT -4. The time now is 01:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy