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

    Send Email when Ping Fails but Email is Empty

    Scheduled Pinned Locked Moved General pfSense Questions
    shell scriptscript tag &&
    2 Posts 2 Posters 702 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.
    • X
      xq1xq1xq1
      last edited by

      When I execute this from the shell it works and I get an email when the ping fails:

      /sbin/ping -S 1*.2*.7*.2* -c 5 1*.1*.1*.*9 | /usr/bin/grep "0 packets received" && { /bin/echo "Site Down now" | /usr/local/bin/mail.php -s"Site Down now" }
      

      The output of the command is:

      5 packets transmitted, 5 packets received, 0.0% packet loss
      {: Command not found.
      

      I receive an email with Subject: "Site Down now" but the content of the email is Empty

      I suspect that there is an error with this part of the command

      { /bin/echo "Site Down now" | /usr/local/bin/mail.php -s"Site Down now" }
      

      which I think is causing this error on the screen:

      {: Command not found.
      

      I am weak on Shell Script but think I have an error with the code syntax the braces or something after the && when the ping fails and the grep succeeds:

      && { /bin/echo "Site Down now" | /usr/local/bin/mail.php -s"Site Down now" }
      

      Thanks in advance for any assistance!

      1 Reply Last reply Reply Quote 0
      • stephenw10S
        stephenw10 Netgate Administrator
        last edited by

        Usually when you see that it's because you're using a bash script and pfSense does not use bash. Some commands do not work.

        Though here it looks like it's trying to run { as a command.

        Steve

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