Skip to content

A lightweight bash-based service to continuously monitor the availability of an IP address using ping, and execute a custom script (e.g., send SMS, email) when the status changes from UP to DOWN or vice versa.

License

Notifications You must be signed in to change notification settings

masoudhb/pingwatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PingWatch

A lightweight bash-based service to continuously monitor the availability of an IP address using ping,
and execute a custom script (e.g., send SMS, email) when the status changes from UP to DOWN or vice versa.

πŸš€ Features

  • Detects server reachability with ICMP ping
  • Verifies failures with a second check after 30 seconds (to avoid false alerts)
  • Triggers custom PHP script on status change
  • Tracks state persistently using a temp file
  • Runs in the background via systemd

πŸ“¦ Files

  • pingwatch.sh: Main bash script
  • pingwatch.service: Example systemd service file
  • send_alert.php: Your custom alert logic (not included, user-defined)

πŸ› οΈ Installation

  1. Clone the repo:

    git clone https://github.com/masoudhb/pingwatch.git
    cd pingwatch
  2. Edit pingwatch.sh and set your:

    • IP to monitor (e.g., IP=8.8.8.8)
    • Path to your PHP alert script
  3. Make it executable:

    chmod +x pingwatch.sh
  4. Create a systemd service at /etc/systemd/system/pingwatch.service:

    [Unit]
    Description=Ping Watcher Service
    After=network.target
    
    [Service]
    ExecStart=/full/path/to/pingwatch.sh
    Restart=always
    
    [Install]
    WantedBy=multi-user.target
  5. Enable and start:

    sudo systemctl daemon-reexec
    sudo systemctl enable pingwatch
    sudo systemctl start pingwatch

πŸ“‹ Example Output

Sat May 24 11:51:07 BST 2025: First ping failed, waiting 30s to recheck...
Sat May 24 11:51:38 BST 2025: Status changed to DOWN
Sat May 24 11:57:18 BST 2025: Status changed to UP

πŸ“„ License

MIT License β€” feel free to use and modify.

About

A lightweight bash-based service to continuously monitor the availability of an IP address using ping, and execute a custom script (e.g., send SMS, email) when the status changes from UP to DOWN or vice versa.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published