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

    How to Ping an IP and run a command when ping failed?

    Scheduled Pinned Locked Moved General pfSense Questions
    3 Posts 2 Posters 277 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.
    • V
      vahitsezer
      last edited by

      Hello,
      I want to ping an IP every minute and when the ping result failed run a command like this:

      pfSsh.php playback svc stop openvpn server 1;
      pfSsh.php playback svc start openvpn server 1;

      Have I any chance about this?

      Thanks

      JKnottJ 1 Reply Last reply Reply Quote 0
      • JKnottJ
        JKnott @vahitsezer
        last edited by

        @vahidmoghadam

        You'd do it with a shell script. Here's one I wrote years ago on Linux:

        #! /bin/sh
        while [ 1 ]
        do
        ping 99.246.124.1 -c 1 || date >> ~/log;sleep 50
        done

        The commands I run on failure are date and sleep for 50 seconds.

        PfSense running on Qotom mini PC
        i5 CPU, 4 GB memory, 32 GB SSD & 4 Intel Gb Ethernet ports.
        UniFi AC-Lite access point

        I haven't lost my mind. It's around here...somewhere...

        V 1 Reply Last reply Reply Quote 1
        • V
          vahitsezer @JKnott
          last edited by vahitsezer

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