Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    /usr/local/bin/mail.php is only executed from the console

    Scheduled Pinned Locked Moved pfSense Packages
    20 Posts 7 Posters 5.2k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • GertjanG
      Gertjan
      last edited by

      Well, all NUT config file are 'owned' bu 'uucp', but I guess it isn't needed.

      I can't do a real 'test' right now, I'm not on site ;)

      Sunday (tomorrow) I'm goint to test-drive it.

      Btw : read http://wiki.ipfire.org/en/addons/nut/start
      and look at the yellow warning:

      the '&' at the and of the sendmail command is mandatory upssched will only wait a few ms for the end of the script but sendmail may take up to 3-5 seconds to send the mail, so upssched will try to hit the trigger again and will also only wait a few ms till it get a return code so in the end it will send 3-5 emails instant of only one. With the & the sendmail command will be send to background an the script returns immediately the error 0 and all are happy :)

      Your not using 'sendmail', you start an instance of php (/usr/local/bin/php) using settings (/usr/local/etc/php.ini) to have /usr/local/bin/mail.php being executed.
      Add the & to that line to have it thrown in the background.

      First line:
      #!/bin/sh
      there was a space in it, remove it (?!)

      No "help me" PM's please. Use the forum, the community will thank you.
      Edit : and where are the logs ??

      1 Reply Last reply Reply Quote 0
      • D
        doktornotor Banned
        last edited by

        "-rwxr-xr-x" is executable for anyone, that's not the problem. But the shebang is indeed obviously wrong.

        1 Reply Last reply Reply Quote 0
        • L
          Lanes
          last edited by

          Fixed the shebang, and added & at the end of the email line - still does not run  ???

          1 Reply Last reply Reply Quote 0
          • GertjanG
            Gertjan
            last edited by

            Hi,

            At this stage, I'm seeing the same results as you do.
            The script runs fine /usr/pbi/nut-amd64/local/etc/nut/upssched-cmd.sh from the command line … but .. no mails (edit: when NUT starts upssched-cmd.sh) .

            Btw: change the definition of "UPSLOG".
            It should read :

            UPSLOG=`clog /var/log/system.log | $grep ups | $tail -5`
            

            I'm still 'fighting' with

            printf "$DATUM\n$*\n\n$EMAIL_CONTENT" | /usr/local/bin/mail.php -s"UPS Alert: $EMAIL_SUBJECT" &
            

            Which is a condensed version - command line works, from script: No.
            It seems to me that /usr/local/bin/mail.php isn't even executed.

            Your questions were helpful to me : it seems that the battery of my UPS is in a bad shape. I have it changed it before I continu testing.

            No "help me" PM's please. Use the forum, the community will thank you.
            Edit : and where are the logs ??

            1 Reply Last reply Reply Quote 0
            • GertjanG
              Gertjan
              last edited by

              I've been trying this week to make this work.

              I used this script:

              #!/bin/sh
              
              WHOAMI=`whoami`
              printf "Script executed by $WHOAMI" | /usr/bin/wall 
              
              logger 1223
              /usr/local/bin/php -q /root/test.php
              logger 5678
              
              exit 0
              

              I know "uupc" (NUT) calls this script, because I found these in the main log:

              Aug 14 12:20:20 	root: 5678
              Aug 14 12:20:20 	root: 1223
              Aug 14 12:20:20 	upsmon[94982]: UPS APC-UPS@localhost on line power
              Aug 14 12:20:15 	root: 5678
              Aug 14 12:20:15 	root: 1223
              Aug 14 12:20:15 	upsmon[94982]: UPS APC-UPS@localhost on battery
              
              

              But : no trace of why this
              /usr/local/bin/php -q /root/test.php
              isn't executed

              Btw: /root/test.php

              #!/usr/local/bin/php -q
              require_once("util.inc");
              
              log_error("In here !!");
              
              ?>
              

              Btw : modo : this thread should be moved to the "Packages" forum.

              No "help me" PM's please. Use the forum, the community will thank you.
              Edit : and where are the logs ??

              1 Reply Last reply Reply Quote 0
              • L
                Lanes
                last edited by

                Unfortunately I have not had any time to research any more into this myself for the past week, so thanks for your efforts. Do we believe this to be a bug, or just some misconfiguration of pfsense/nut?

                I have a few things I want to test when given the opportunity:

                1. Can the NOTIFYCMD script call / execute any non-php file
                2. Does the issue remain if we set NUT to use upssched, and then call the php script via the CMDSCRIPT variable instead
                3. Does the issue remain if we do write the commands inline in upsmon (NOTIFYCMD = 'do stuff here')
                1 Reply Last reply Reply Quote 0
                • L
                  Lanes
                  last edited by

                  I got bored trying to find a solution for this issue back in August, and I have not looked at it until today. Since August there has been a few updates of the NUT package that I silently hoped would fix my issue, but no luck. I still can't get any php script to trigger from NUT, and I am at a loss where to look next.

                  Where can I report this issue?

                  1 Reply Last reply Reply Quote 0
                  • jimpJ
                    jimp Rebel Alliance Developer Netgate
                    last edited by

                    have you tried:

                    /usr/local/bin/php -f /usr/local/bin/mail.php
                    

                    Rather than executing it directly?

                    Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

                    Need help fast? Netgate Global Support!

                    Do not Chat/PM for help!

                    1 Reply Last reply Reply Quote 0
                    • L
                      Lanes
                      last edited by

                      Tried that, and I have lost count for how many variations I have tried. It just won't execute the php. I am now using the same script as Gertjan posted above to test, and I have the exact same results as he.

                      1 Reply Last reply Reply Quote 0
                      • R
                        ryan87
                        last edited by

                        I have the same issue.  I've never been able to get it working.  There's a related feature request here.

                        1 Reply Last reply Reply Quote 0
                        • L
                          Lanes
                          last edited by

                          Good find ryanjaeb, I had not come across that for all my searching. I am a bit disappointed by the feature not being in place, but at least it appears the issue is not on my end.

                          On a related topic: How do you guys then monitor the status of your UPS? I suppose I can create a separate log file, and possibly monitor that for changes to send email notifications. It would not be instant, but it could work.

                          1 Reply Last reply Reply Quote 0
                          • L
                            larathydo
                            last edited by

                            Hi Everyone,

                            I'm going absolutely mad myself trying to get email notification functionality to work via the NUT package and NOTIFYCMD via upsmon.conf options.

                            Has anyone been able to get this to work? I too tried to use mail.php but nothing ever happens. The same command in the console works just great.

                            Can anyone think of another alternative method to facilitate basic email functionality though something other than mail.php if we're hitting this limitation? As in, I wonder if we could still call a script via NOTIFYCMD but instead of the script relying on mail.php, it could use some other mechanism to send the email?

                            This is so aggravating! Has anyone ever got NUT email functionality to work in any way-shape-form?

                            1 Reply Last reply Reply Quote 0
                            • jimpJ
                              jimp Rebel Alliance Developer Netgate
                              last edited by

                              FYI- Though NUT is not yet on 2.3, using mail.php from the GUI and elsewhere appears to work on 2.3 where it did not on 2.2.x. Might be the difference in PHP versions or other changes to PHP handling, but at least from the tests I was able to run, it sent messages to me when it wouldn't otherwise.

                              Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

                              Need help fast? Netgate Global Support!

                              Do not Chat/PM for help!

                              1 Reply Last reply Reply Quote 0
                              • C
                                Carltonson-sky
                                last edited by

                                hi everybody,

                                Can you tell me how to use mail.php under 2.3 release please. I’m looking for the syntax but without success. can you give me an example ? I try to send an email to the people who filled my php form.
                                Thanks in advance

                                cheers

                                1 Reply Last reply Reply Quote 0
                                • jimpJ
                                  jimp Rebel Alliance Developer Netgate
                                  last edited by

                                  @Carltonson-sky:

                                  Can you tell me how to use mail.php under 2.3 release please. I’m looking for the syntax but without success. can you give me an example ? I try to send an email to the people who filled my php form.

                                  Not likely to be usable for that. It's for basic mail from the CLI:

                                  echo test | mail.php -s="Blah"
                                  

                                  Start a new thread in the appropriate forum (not here) and maybe someone can help come up with a way to do what you're after.

                                  Hosting a form like that on the firewall is not something we'd recommend, however.

                                  Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

                                  Need help fast? Netgate Global Support!

                                  Do not Chat/PM for help!

                                  1 Reply Last reply Reply Quote 0
                                  • First post
                                    Last post
                                  Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.