> For the complete documentation index, see [llms.txt](https://wiki.smhuda.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.smhuda.com/programming/automation/network-connectivity-cron.md).

# Network Connectivity Cron

This script checks if the network manager is running or if there is network connectivity, if not it restarts network manager. Great for cronjobs to check every 2 minutes to ensure remotely managed machines always stay online.

Copy the following script in the a new file, in this case I'm calling it check\_network. Place it at the following location:

`/usr/local/bin/check_network`

```
#!/bin/bash

if ping 8.8.8.8 ; then
	:
else
	service network-manager restart
fi
```

Add the following line to `/etc/crontab`. Change the `*/2` to whatever increment you want to have this script run in minutes. It's currently set to run `/usr/local/bin/check_network` every two minutes.

```
*/2 * * * * root /usr/local/bin/check_network
```

Set the execute permissions on the script. As root, type:&#x20;

```
chmod +x /usr/local/bin/check_network
```

To ensure the cronjob is running or not. Running the “systemctl” command along with the status flag will check the status of the Cron service as shown in the image below. If the status is “Active (Running)” then it will be confirmed that crontab is working perfectly well, otherwise not.

```
$ systemctl status cron
```

To edit or add/remove cron jobs:

```
$ crontab –e
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://wiki.smhuda.com/programming/automation/network-connectivity-cron.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
