Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?


Failed to load latest commit information.
Latest commit message
Commit time

GitHub Issues Total Commits GitHub commit activity License Contributions welcome

Network Repair/Reboot Automation

This bash script checks the health status for either wired or wireless internet connection and, if it is failing, tries to fix it.

Tested Platforms

  • GNU/Linux, Debian 10 - Buster
  • Raspberry Pi, Raspbian 10 - Buster
  • ReadyNAS, 6.10.3


GNU / Linux ping command is the only requirement and it should be available on most systems which already have networking.
In case your system does not have ping it is possible to install it using this command:
sudo apt-get install -y iputils-ping

How to use

  • Clone (or download) this repo locally:
    git clone
  • Make the script executable:
    sudo chmod +x
  • (Optional) If your network card name is not wlan0, you should replace it with the correct name. For example to use the name of the currently connected card:
    sed -i 's/wlan0/'"$(ip route get | head -n1 | cut -d' ' -f5)"'/'
    (note for MacOS users, use gsed or add an argument sed -i '' ...)
  • Edit your root user's crontab using:
    sudo crontab -e
  • Add to your crontab the following line, it will execute the check every minute. Please customize the script path according to the folder where you cloned the repo:
    * * * * * /yourpath/ >> /var/log/netcheck.log 2>&1
  • If you also want to reboot in case the network is not working after the fix customize the reboot_server variable accordigly editing the script using vi (or your preferred editor):
  • The script contains VERY verbose comments and explanations in order to make it friendly and easy to modify for young and / or inexperienced BASH users. If you are an expert you will find those terrible and boring, here's a snippet to remove all comments in one go:
    grep -o '^[^#]*'

Optional - Push notifications / Email

If you want to add push or email notifications when your network is restored please check my other repo, Simple Notifications

Optional - Automatic repair with fsck in case of reboot

As a last thing, if you want to perform automatic repair with fsck in case of reboot (even if it slows down the boot a bit I think it is quite a good idea to do it) remember to enable the functionality on your system.
How to enable this funcionality changes according to your OS and its version, here's a possible way to configure it on Debian Buster (Raspberry Pi):

  • Edit /boot/cmdline.txt
  • Be sure that you have in it the following lines:

You'll probably notice is already there; these two properties are not exactly the same thing. From man systemd-fsck (these are actually parameters that are passed on by the kernel to init, i.e., systemd):


One of "auto", "force", "skip". Controls the mode of operation. The default is "auto", and ensures that file system checks are done when the file system checker deems them necessary. "force" unconditionally results in full file system checks. "skip" skips any file system checks.

One of "preen", "yes", "no". Controls the mode of operation. The default is "preen", and will automatically repair problems that can be safely fixed. "yes " will answer yes to all questions by fsck and "no" will answer no to all questions.

Release History

  • 0.1.1
    • Added multiple ip functionality for gateway check
  • 0.1.0
    • Removed all dependencies
    • Added reboot-loop prevention
  • 0.0.3
    • Ifupdown is not compatible with udev, in order to extend compatibility with other systems like NAS its requirement was made optional
    • Added logging
  • 0.0.2
    • Refactored in order to remove tmp files and preserve Raspberry's SD card
  • 0.0.1
    • First working version using tmp files to keep count of the network check retries


Davide Nastri –

Distributed under the GPL license. See LICENSE for more information.

Bash Wifi Network Repair Script


  1. Fork it (
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Contributors (thanks, you are awesome! :) )

  1. czerwony03 -> bug: fixed wrong apostrophe
  2. pattyland -> Added absolute path if root does not have sbin in path
  3. deltabravozulu -> Make ifupdown optional for udev users
  4. mpatnode -> Use regular ping. Add reboot loop prevention
  5. m3at -> Allow for multiple check hosts/IPs
  6. pcchynoweth -> Feature/add note interface


This bash script checks the health status for either wired or wireless internet connection and, if it is failing, tries to fix it.








No releases published


No packages published