Send Email when Ping Fails but Email is Empty

  • 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!

  • Netgate Administrator

    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.